Skip to content

fix(drag-drop): restore initial transform when resetting #14701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
14 changes: 14 additions & 0 deletions src/cdk/drag-drop/directives/drag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,20 @@ describe('CdkDrag', () => {
expect(dragElement.style.transform).toBeFalsy();
}));

it('should preserve initial transform after resetting', fakeAsync(() => {
const fixture = createComponent(StandaloneDraggable);
fixture.detectChanges();
const dragElement = fixture.componentInstance.dragElement.nativeElement;

dragElement.style.transform = 'scale(2)';

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

fixture.componentInstance.dragInstance.reset();
expect(dragElement.style.transform).toBe('scale(2)');
}));

it('should start dragging an item from its initial position after a reset', fakeAsync(() => {
const fixture = createComponent(StandaloneDraggable);
fixture.detectChanges();
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/drag-drop/drag-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export class DragRef<T = any> {

/** Resets a standalone drag item to its initial position. */
reset(): void {
this._rootElement.style.transform = '';
this._rootElement.style.transform = this._initialTransform || '';
this._activeTransform = {x: 0, y: 0};
this._passiveTransform = {x: 0, y: 0};
}
Expand Down