Skip to content

Commit

Permalink
fix(drag-drop): preview position relative to cursor thrown off if ite…
Browse files Browse the repository at this point in the history
…m has margin (#16180)

Fixes the preview shifting sideways relative to the cursor, if the item that's being dragged has a margin.

Fixes #16171.
  • Loading branch information
crisbeto authored and jelbourn committed Sep 9, 2019
1 parent 7bf5e4e commit 46cf45f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/cdk/drag-drop/directives/drag.spec.ts
Expand Up @@ -1765,6 +1765,8 @@ describe('CdkDrag', () => {
expect(previewRect.height).toBe(itemRect.height, 'Expected preview height to match element');
expect(preview.style.pointerEvents)
.toBe('none', 'Expected pointer events to be disabled on the preview');
// Use a regex here since some browsers normalize 0 to 0px, but others don't.
expect(preview.style.margin).toMatch(/^0(px)?$/, 'Expected the preview margin to be reset.');

dispatchMouseEvent(document, 'mouseup');
fixture.detectChanges();
Expand Down
2 changes: 2 additions & 0 deletions src/cdk/drag-drop/drag-ref.ts
Expand Up @@ -867,6 +867,8 @@ export class DragRef<T = any> {
// It's important that we disable the pointer events on the preview, because
// it can throw off the `document.elementFromPoint` calls in the `CdkDropList`.
pointerEvents: 'none',
// We have to reset the margin, because can throw off positioning relative to the viewport.
margin: '0',
position: 'fixed',
top: '0',
left: '0',
Expand Down

0 comments on commit 46cf45f

Please sign in to comment.