Skip to content

Commit 32f990a

Browse files
crisbetoVivian Hu
authored and
Vivian Hu
committedJan 18, 2019
fix(drag-drop): restore initial transform when resetting (#14701)
Currently we preserve the any `transform` that an element might have had before the user started dragging it, however that `transform` is lost if it's position is reset via the `DragRef.reset` method. These changes reset the `transform` back to its initial value.
1 parent 7322977 commit 32f990a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
 

‎src/cdk/drag-drop/directives/drag.spec.ts

+14
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,20 @@ describe('CdkDrag', () => {
578578
expect(dragElement.style.transform).toBeFalsy();
579579
}));
580580

581+
it('should preserve initial transform after resetting', fakeAsync(() => {
582+
const fixture = createComponent(StandaloneDraggable);
583+
fixture.detectChanges();
584+
const dragElement = fixture.componentInstance.dragElement.nativeElement;
585+
586+
dragElement.style.transform = 'scale(2)';
587+
588+
dragElementViaMouse(fixture, dragElement, 50, 100);
589+
expect(dragElement.style.transform).toBe('scale(2) translate3d(50px, 100px, 0px)');
590+
591+
fixture.componentInstance.dragInstance.reset();
592+
expect(dragElement.style.transform).toBe('scale(2)');
593+
}));
594+
581595
it('should start dragging an item from its initial position after a reset', fakeAsync(() => {
582596
const fixture = createComponent(StandaloneDraggable);
583597
fixture.detectChanges();

‎src/cdk/drag-drop/drag-ref.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ export class DragRef<T = any> {
374374

375375
/** Resets a standalone drag item to its initial position. */
376376
reset(): void {
377-
this._rootElement.style.transform = '';
377+
this._rootElement.style.transform = this._initialTransform || '';
378378
this._activeTransform = {x: 0, y: 0};
379379
this._passiveTransform = {x: 0, y: 0};
380380
}

0 commit comments

Comments
 (0)
Please sign in to comment.