Skip to content

Commit 021b85a

Browse files
crisbetommalerba
authored andcommitted
fix(drag-drop): not reacting to changes in the cdkDragFreeDragPosition (#15805)
Fixes the `CdkDrag` not reacting to changes in the `cdkDragFreeDragPosition` input, because we had mispelled something and it wasn't caught by TS since `SimpleChanges` isn't typed. Fixes #15765.
1 parent a23d787 commit 021b85a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,21 @@ describe('CdkDrag', () => {
816816
expect(dragInstance.getFreeDragPosition()).toEqual({x: 50, y: 100});
817817
}));
818818

819+
it('should react to changes in the free drag position', fakeAsync(() => {
820+
const fixture = createComponent(StandaloneDraggable);
821+
fixture.componentInstance.freeDragPosition = {x: 50, y: 100};
822+
fixture.detectChanges();
823+
824+
const dragElement = fixture.componentInstance.dragElement.nativeElement;
825+
826+
expect(dragElement.style.transform).toBe('translate3d(50px, 100px, 0px)');
827+
828+
fixture.componentInstance.freeDragPosition = {x: 100, y: 200};
829+
fixture.detectChanges();
830+
831+
expect(dragElement.style.transform).toBe('translate3d(100px, 200px, 0px)');
832+
}));
833+
819834
it('should be able to continue dragging after the current position was set', fakeAsync(() => {
820835
const fixture = createComponent(StandaloneDraggable);
821836
fixture.componentInstance.freeDragPosition = {x: 50, y: 100};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
258258

259259
ngOnChanges(changes: SimpleChanges) {
260260
const rootSelectorChange = changes['rootElementSelector'];
261-
const positionChange = changes['positionChange'];
261+
const positionChange = changes['freeDragPosition'];
262262

263263
// We don't have to react to the first change since it's being
264264
// handled in `ngAfterViewInit` where it needs to be deferred.

0 commit comments

Comments
 (0)