diff --git a/src/cdk/drag-drop/directives/drag.spec.ts b/src/cdk/drag-drop/directives/drag.spec.ts index 9929fbb081ac..5f36fa9dfb1f 100644 --- a/src/cdk/drag-drop/directives/drag.spec.ts +++ b/src/cdk/drag-drop/directives/drag.spec.ts @@ -1502,6 +1502,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(); diff --git a/src/cdk/drag-drop/drag-ref.ts b/src/cdk/drag-drop/drag-ref.ts index 0a49673af560..f6c5a52d13c1 100644 --- a/src/cdk/drag-drop/drag-ref.ts +++ b/src/cdk/drag-drop/drag-ref.ts @@ -814,6 +814,8 @@ export class DragRef { // 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',