Skip to content

fix(cdk/drag-drop): not blocking initial move event #21752

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
Feb 5, 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
6 changes: 4 additions & 2 deletions src/cdk/drag-drop/directives/drag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,10 @@ describe('CdkDrag', () => {
dispatchTouchEvent(fixture.componentInstance.dragElement.nativeElement, 'touchstart');
fixture.detectChanges();

dispatchTouchEvent(document, 'touchmove');
expect(dispatchTouchEvent(document, 'touchmove').defaultPrevented).toBe(true);
expect(dispatchTouchEvent(document, 'touchmove').defaultPrevented)
.toBe(true, 'Expected initial touchmove to be prevented.');
expect(dispatchTouchEvent(document, 'touchmove').defaultPrevented)
.toBe(true, 'Expected subsequent touchmose to be prevented.');

dispatchTouchEvent(document, 'touchend');
fixture.detectChanges();
Expand Down
3 changes: 3 additions & 0 deletions src/cdk/drag-drop/drag-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,9 @@ export class DragRef<T = any> {
// being dragged. This can happen while we're waiting for the drop animation to finish
// and can cause errors, because some elements might still be moving around.
if (!container || (!container.isDragging() && !container.isReceiving())) {
// Prevent the default action as soon as the dragging sequence is considered as
// "started" since waiting for the next event can allow the device to begin scrolling.
event.preventDefault();
this._hasStartedDragging = true;
this._ngZone.run(() => this._startDragSequence(event));
}
Expand Down