Skip to content

fix(drag-drop): not reacting to changes in the cdkDragFreeDragPosition #15805

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 1 commit into from
Apr 23, 2019
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
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