Skip to content

Commit 83d82b9

Browse files
authored
fix(cdk/drag-drop): element not draggable when has initial transform … (#22458)
* fix(cdk/drag-drop): element not draggable when has initial transform none * fix(cdk/drag-drop): fix for recommended changes to code and tests cases
1 parent 56a30d0 commit 83d82b9

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,18 @@ describe('CdkDrag', () => {
407407
}));
408408
});
409409

410+
describe('mouse dragging when initial transform is none', () => {
411+
it('should drag an element freely to a particular position', fakeAsync(() => {
412+
const fixture = createComponent(StandaloneDraggable);
413+
fixture.detectChanges();
414+
const dragElement = fixture.componentInstance.dragElement.nativeElement;
415+
dragElement.style.transform = 'none';
416+
417+
dragElementViaMouse(fixture, dragElement, 50, 100);
418+
expect(dragElement.style.transform).toBe('translate3d(50px, 100px, 0px)');
419+
}));
420+
});
421+
410422
it('should dispatch an event when the user has started dragging', fakeAsync(() => {
411423
const fixture = createComponent(StandaloneDraggable);
412424
fixture.detectChanges();

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1277,8 +1277,12 @@ export class DragRef<T = any> {
12771277

12781278
// Cache the previous transform amount only after the first drag sequence, because
12791279
// we don't want our own transforms to stack on top of each other.
1280+
// Should be excluded none because none + translate3d(x, y, x) is invalid css
12801281
if (this._initialTransform == null) {
1281-
this._initialTransform = this._rootElement.style.transform || '';
1282+
this._initialTransform = this._rootElement.style.transform
1283+
&& this._rootElement.style.transform != 'none'
1284+
? this._rootElement.style.transform
1285+
: '';
12821286
}
12831287

12841288
// Preserve the previous `transform` value, if there was one. Note that we apply our own

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,7 @@ export function toggleVisibility(element: HTMLElement,
8282
* that exited before the base transform was applied.
8383
*/
8484
export function combineTransforms(transform: string, initialTransform?: string): string {
85-
return initialTransform ? (transform + ' ' + initialTransform) : transform;
85+
return initialTransform && initialTransform != 'none' ?
86+
(transform + ' ' + initialTransform) :
87+
transform;
8688
}

0 commit comments

Comments
 (0)