diff --git a/src/cdk/drag-drop/directives/drag.spec.ts b/src/cdk/drag-drop/directives/drag.spec.ts index 7bdae5b6d3db..85b97a61ebf4 100644 --- a/src/cdk/drag-drop/directives/drag.spec.ts +++ b/src/cdk/drag-drop/directives/drag.spec.ts @@ -407,6 +407,18 @@ describe('CdkDrag', () => { })); }); + describe('mouse dragging when initial transform is none', () => { + it('should drag an element freely to a particular position', fakeAsync(() => { + const fixture = createComponent(StandaloneDraggable); + fixture.detectChanges(); + const dragElement = fixture.componentInstance.dragElement.nativeElement; + dragElement.style.transform = 'none'; + + dragElementViaMouse(fixture, dragElement, 50, 100); + expect(dragElement.style.transform).toBe('translate3d(50px, 100px, 0px)'); + })); + }); + it('should dispatch an event when the user has started dragging', fakeAsync(() => { const fixture = createComponent(StandaloneDraggable); fixture.detectChanges(); diff --git a/src/cdk/drag-drop/drag-ref.ts b/src/cdk/drag-drop/drag-ref.ts index 05c3db7df8b6..37e2a64f7d92 100644 --- a/src/cdk/drag-drop/drag-ref.ts +++ b/src/cdk/drag-drop/drag-ref.ts @@ -1277,8 +1277,12 @@ export class DragRef { // Cache the previous transform amount only after the first drag sequence, because // we don't want our own transforms to stack on top of each other. + // Should be excluded none because none + translate3d(x, y, x) is invalid css if (this._initialTransform == null) { - this._initialTransform = this._rootElement.style.transform || ''; + this._initialTransform = this._rootElement.style.transform + && this._rootElement.style.transform != 'none' + ? this._rootElement.style.transform + : ''; } // Preserve the previous `transform` value, if there was one. Note that we apply our own diff --git a/src/cdk/drag-drop/drag-styling.ts b/src/cdk/drag-drop/drag-styling.ts index d1c2d4e83865..82145fce7d6a 100644 --- a/src/cdk/drag-drop/drag-styling.ts +++ b/src/cdk/drag-drop/drag-styling.ts @@ -82,5 +82,7 @@ export function toggleVisibility(element: HTMLElement, * that exited before the base transform was applied. */ export function combineTransforms(transform: string, initialTransform?: string): string { - return initialTransform ? (transform + ' ' + initialTransform) : transform; + return initialTransform && initialTransform != 'none' ? + (transform + ' ' + initialTransform) : + transform; }