Skip to content
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
4 changes: 4 additions & 0 deletions src/cdk/drag-drop/directives/drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
() => {
this._updateRootElement();
this._setupHandlesListener();
this._dragRef.scale = this.scale;

if (this.freeDragPosition) {
this._dragRef.setFreeDragPosition(this.freeDragPosition);
Expand All @@ -333,6 +334,9 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
this._updateRootElement();
}

// Scale affects the free drag position so we need to sync it up here.
this._dragRef.scale = this.scale;

// Skip the first change since it's being handled in the `afterNextRender` queued up in the
// constructor.
if (positionChange && !positionChange.firstChange && this.freeDragPosition) {
Expand Down
14 changes: 14 additions & 0 deletions src/cdk/drag-drop/directives/standalone-drag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,20 @@ describe('Standalone CdkDrag', () => {
expect(dragElement.style.transform).toBe('translate3d(150px, 300px, 0px)');
}));

it('should account for the scale when setting the free drag position', fakeAsync(() => {
const fixture = createComponent(StandaloneDraggable);
fixture.componentInstance.scale = 0.5;
fixture.componentInstance.freeDragPosition = {x: 50, y: 100};
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();

const dragElement = fixture.componentInstance.dragElement.nativeElement;
const dragInstance = fixture.componentInstance.dragInstance;

expect(dragElement.style.transform).toBe('translate3d(100px, 200px, 0px)');
expect(dragInstance.getFreeDragPosition()).toEqual({x: 50, y: 100});
}));

it('should include the dragged distance as the user is dragging', fakeAsync(() => {
const fixture = createComponent(StandaloneDraggable);
fixture.detectChanges();
Expand Down
Loading