Skip to content

Commit fbb2a13

Browse files
crisbetojelbourn
authored andcommitted
fix(drag-drop): unable to stop dragging after quick double click (#14506)
Seems to be something that regressed while we were doing the recent refactor. When starting a drag after a quick double-click sequence, the user can't stop dragging.
1 parent 792d536 commit fbb2a13

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,29 @@ describe('CdkDrag', () => {
159159
expect(dragElement.style.transform).toBeFalsy();
160160
}));
161161

162+
it('should be able to stop dragging after a double click', fakeAsync(() => {
163+
const fixture = createComponent(StandaloneDraggable, [], 5);
164+
fixture.detectChanges();
165+
const dragElement = fixture.componentInstance.dragElement.nativeElement;
166+
167+
expect(dragElement.style.transform).toBeFalsy();
168+
169+
dispatchMouseEvent(dragElement, 'mousedown');
170+
fixture.detectChanges();
171+
dispatchMouseEvent(document, 'mouseup');
172+
fixture.detectChanges();
173+
dispatchMouseEvent(dragElement, 'mousedown');
174+
fixture.detectChanges();
175+
dispatchMouseEvent(document, 'mouseup');
176+
fixture.detectChanges();
177+
178+
dragElementViaMouse(fixture, dragElement, 50, 50);
179+
dispatchMouseEvent(document, 'mousemove', 100, 100);
180+
fixture.detectChanges();
181+
182+
expect(dragElement.style.transform).toBeFalsy();
183+
}));
184+
162185
it('should preserve the previous `transform` value', fakeAsync(() => {
163186
const fixture = createComponent(StandaloneDraggable);
164187
fixture.detectChanges();

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,11 @@ export class DragRef<T = any> {
505505

506506
/** Handler that is invoked when the user lifts their pointer up, after initiating a drag. */
507507
private _pointerUp = (event: MouseEvent | TouchEvent) => {
508-
if (!this.isDragging()) {
508+
// Note that here we use `isDragging` from the service, rather than from `this`.
509+
// The difference is that the one from the service reflects whether a dragging sequence
510+
// has been initiated, whereas the one on `this` includes whether the user has passed
511+
// the minimum dragging threshold.
512+
if (!this._dragDropRegistry.isDragging(this)) {
509513
return;
510514
}
511515

0 commit comments

Comments
 (0)