Skip to content

fix(cdk/drag-drop): element not draggable when has initial transform … #22458

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 2 commits into from
Jul 28, 2021
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
12 changes: 12 additions & 0 deletions src/cdk/drag-drop/directives/drag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion src/cdk/drag-drop/drag-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1277,8 +1277,12 @@ export class DragRef<T = any> {

// 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
Expand Down
4 changes: 3 additions & 1 deletion src/cdk/drag-drop/drag-styling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}