Skip to content

Commit

Permalink
fix(drag-drop): not reacting to changes in the cdkDragFreeDragPosition
Browse files Browse the repository at this point in the history
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 angular#15765.
  • Loading branch information
crisbeto committed Apr 12, 2019
1 parent f6edba3 commit 3f4afdc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/cdk/drag-drop/directives/drag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,21 @@ describe('CdkDrag', () => {
expect(dragInstance.getFreeDragPosition()).toEqual({x: 50, y: 100});
}));

it('should react to changes in the free drag position', fakeAsync(() => {
const fixture = createComponent(StandaloneDraggable);
fixture.componentInstance.freeDragPosition = {x: 50, y: 100};
fixture.detectChanges();

const dragElement = fixture.componentInstance.dragElement.nativeElement;

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

fixture.componentInstance.freeDragPosition = {x: 100, y: 200};
fixture.detectChanges();

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

it('should be able to continue dragging after the current position was set', fakeAsync(() => {
const fixture = createComponent(StandaloneDraggable);
fixture.componentInstance.freeDragPosition = {x: 50, y: 100};
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/drag-drop/directives/drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {

ngOnChanges(changes: SimpleChanges) {
const rootSelectorChange = changes['rootElementSelector'];
const positionChange = changes['positionChange'];
const positionChange = changes['freeDragPosition'];

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

0 comments on commit 3f4afdc

Please sign in to comment.