Skip to content

fix(drag-drop): multiple parallel drag sequences when dragging nested drag items #13820

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
Nov 3, 2018
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
14 changes: 14 additions & 0 deletions src/cdk/drag-drop/drag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,20 @@ describe('CdkDrag', () => {
expect(dragElement.style.transform).toBeFalsy();
}));

it('should stop propagation for the drag sequence start event', fakeAsync(() => {
const fixture = createComponent(StandaloneDraggable);
fixture.detectChanges();
const dragElement = fixture.componentInstance.dragElement.nativeElement;

const event = createMouseEvent('mousedown');
spyOn(event, 'stopPropagation').and.callThrough();

dispatchEvent(dragElement, event);
fixture.detectChanges();

expect(event.stopPropagation).toHaveBeenCalled();
}));

});

describe('draggable with a handle', () => {
Expand Down
7 changes: 5 additions & 2 deletions src/cdk/drag-drop/drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,13 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
* @param event Browser event object that started the sequence.
*/
private _initializeDragSequence(referenceElement: HTMLElement, event: MouseEvent | TouchEvent) {
const isDragging = this._isDragging();
// Always stop propagation for the event that initializes
// the dragging sequence, in order to prevent it from potentially
// starting another sequence for a draggable parent somewhere up the DOM tree.
event.stopPropagation();

// Abort if the user is already dragging or is using a mouse button other than the primary one.
if (isDragging || (!this._isTouchEvent(event) && event.button !== 0)) {
if (this._isDragging() || (!this._isTouchEvent(event) && event.button !== 0)) {
return;
}

Expand Down