Skip to content
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

bug(@angular/cdk): dragStart event completely blocked within cdkDrag element #24533

Closed
1 task done
loebi-ch opened this issue Mar 7, 2022 · 7 comments · Fixed by #24581
Closed
1 task done

bug(@angular/cdk): dragStart event completely blocked within cdkDrag element #24533

loebi-ch opened this issue Mar 7, 2022 · 7 comments · Fixed by #24581
Assignees
Labels
area: cdk/drag-drop P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@loebi-ch
Copy link

loebi-ch commented Mar 7, 2022

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

13.2.3

Description

Inside a Angular's cdkDropList I use another third party library for sorting a grid (display:flex; flex-wrap:wrap) with Drag'n'Drop. After upgrading Angular's CDK from version 13.2.3 to 13.2.4 this third party component stopped working.

After some detailed research I've found the root cause in cdk/drag-drop/drag-ref.ts:

image

With this added line you'll break the dragstart event, what makes it impossible to use any other drag'n'drop functionality within CDK's Drag'n'Drop functionality.

Reproduction

No steps to reproduce.

Expected Behavior

The dragstart event should still be fired within an cdkDrag element.

Actual Behavior

dragstart event is completely blocked with event.preventDefault(), which makes it absolutely impossible to use Angular's Drag'n'Drop functionality with custom or even native Drag'n'Drop functionality inside.

Environment

  • Angular: 13.2.4
  • CDK/Material: 13.2.4
  • Browser(s): Google Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows
@crisbeto
Copy link
Member

crisbeto commented Mar 7, 2022

In general we don't make changes to accommodate other libraries, because it would be really difficult to support all of the possible combinations.

@loebi-ch
Copy link
Author

loebi-ch commented Mar 7, 2022

It's not only related to third party libraries. You break the native browser's dragstart event. And I even don't understand why.

@crisbeto
Copy link
Member

crisbeto commented Mar 7, 2022

The whole point of the cdk/drag-drop library is to be an alternative to native dragging. We're preventing many more native interactions, not just the dragstart (e.g. mouse clicks, scrolling), in order to prevent them from interfering with the dragging.

@loebi-ch
Copy link
Author

loebi-ch commented Mar 7, 2022

I've just read #24403 and I do understand your point.

BUT: Actually if I use CDK's cdkDragHandle option, then the dragstart event should not be blocked for the whole cdkDrag element, but only the handle element. Don't you agree?

@loebi-ch
Copy link
Author

loebi-ch commented Mar 7, 2022

I have found a solution for my problem. Inside a cdkDrag element I use (dragstart)="$event.stopPropagation()":

<div cdkDropList>
	 <div class="block" cdkDrag>
		<span cdkDragHandle>HANDLE</span> Block 1
	 </div>
	 <div class="block" cdkDrag>
		<span cdkDragHandle>HANDLE</span> Block 2
		<div (dragstart)="$event.stopPropagation()">
			<!-- Now I can use navtive Drag'n'Drop (or third party library) here again -->
		</div>
	 </div>
</div>

I still think that the dragstart event should only be blocked for the handle element and not the whole cdkDrag element when using cdkDragHandle.

Best regards,
Andy

@crisbeto crisbeto self-assigned this Mar 12, 2022
@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent has pr area: cdk/drag-drop and removed needs triage This issue needs to be triaged by the team labels Mar 12, 2022
crisbeto added a commit to crisbeto/material2 that referenced this issue Mar 12, 2022
Currently we block the `dragstart` event on the entire drag element which doesn't account for its disabled state and for any existing handles.

Fixes angular#24533.
@crisbeto
Copy link
Member

That makes sense, it's how the mousedown/touchstart event works as well. I've sent out #24581 to fix it.

crisbeto added a commit that referenced this issue Mar 12, 2022
Currently we block the `dragstart` event on the entire drag element which doesn't account for its disabled state and for any existing handles.

Fixes #24533.

(cherry picked from commit 45fae71)
crisbeto added a commit that referenced this issue Mar 12, 2022
Currently we block the `dragstart` event on the entire drag element which doesn't account for its disabled state and for any existing handles.

Fixes #24533.
forsti0506 pushed a commit to forsti0506/components that referenced this issue Apr 3, 2022
…lar#24581)

Currently we block the `dragstart` event on the entire drag element which doesn't account for its disabled state and for any existing handles.

Fixes angular#24533.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: cdk/drag-drop P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants