Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/cdk/drag-drop/directives/drag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,23 @@ describe('CdkDrag', () => {
expect(dragElement.style.transform).toBe('translate3d(50px, 100px, 0px)');
}));

it('should keep the old position if the boundary is invisible after a resize', fakeAsync(() => {
const fixture = createComponent(StandaloneDraggable);
const boundary: HTMLElement = fixture.nativeElement.querySelector('.wrapper');
fixture.componentInstance.boundary = boundary;
fixture.detectChanges();
const dragElement = fixture.componentInstance.dragElement.nativeElement;

dragElementViaMouse(fixture, dragElement, 300, 300);
expect(dragElement.style.transform).toBe('translate3d(100px, 100px, 0px)');

boundary.style.display = 'none';
dispatchFakeEvent(window, 'resize');
tick(20);

expect(dragElement.style.transform).toBe('translate3d(100px, 100px, 0px)');
}));

it('should handle the element and boundary dimensions changing between drag sequences',
fakeAsync(() => {
const fixture = createComponent(StandaloneDraggable);
Expand Down
8 changes: 8 additions & 0 deletions src/cdk/drag-drop/drag-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,14 @@ export class DragRef<T = any> {

const boundaryRect = this._boundaryElement.getBoundingClientRect();
const elementRect = this._rootElement.getBoundingClientRect();

// It's possible that the element got hidden away after dragging (e.g. by switching to a
// different tab). Don't do anything in this case so we don't clear the user's position.
if ((boundaryRect.width === 0 && boundaryRect.height === 0) ||
(elementRect.width === 0 && elementRect.height === 0)) {
return;
}

const leftOverflow = boundaryRect.left - elementRect.left;
const rightOverflow = elementRect.right - boundaryRect.right;
const topOverflow = boundaryRect.top - elementRect.top;
Expand Down