Skip to content

fix(drag-drop): unable to stop dragging after quick double click #14506

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

it('should be able to stop dragging after a double click', fakeAsync(() => {
const fixture = createComponent(StandaloneDraggable, [], 5);
fixture.detectChanges();
const dragElement = fixture.componentInstance.dragElement.nativeElement;

expect(dragElement.style.transform).toBeFalsy();

dispatchMouseEvent(dragElement, 'mousedown');
fixture.detectChanges();
dispatchMouseEvent(document, 'mouseup');
fixture.detectChanges();
dispatchMouseEvent(dragElement, 'mousedown');
fixture.detectChanges();
dispatchMouseEvent(document, 'mouseup');
fixture.detectChanges();

dragElementViaMouse(fixture, dragElement, 50, 50);
dispatchMouseEvent(document, 'mousemove', 100, 100);
fixture.detectChanges();

expect(dragElement.style.transform).toBeFalsy();
}));

it('should preserve the previous `transform` value', 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 @@ -495,7 +495,11 @@ export class DragRef<T = any> {

/** Handler that is invoked when the user lifts their pointer up, after initiating a drag. */
private _pointerUp = (event: MouseEvent | TouchEvent) => {
if (!this.isDragging()) {
// Note that here we use `isDragging` from the service, rather than from `this`.
// The difference is that the one from the service reflects whether a dragging sequence
// has been initiated, whereas the one on `this` includes whether the user has passed
// the minimum dragging threshold.
if (!this._dragDropRegistry.isDragging(this)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment that explains why this is not using this.isDragging()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return;
}

Expand Down