question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does cdkDrag suppress native drag and drop events?

See original GitHub issue

What are you trying to do?

Use native drag and drop events such as dragstart, dragenter and dragexit in conjunction with cdkDrag. Without these it’s hard to build richer behaviours in as well as things like visually highlighting the drop zone.

What troubleshooting steps have you tried?

I have tried attaching these events to both the container list and the individual draggable list items but they don’t seem to fire.

Reproduction

https://components-issue-un5pqw.stackblitz.io

Steps to reproduce:

  1. Go to the stackblitz
  2. Try dragging items in the list
  3. Notice that the ondragstart event doesn’t fire
  4. Try adding other native drag events and see whether they work - I can’t seem to make them do so

Environment

  • Angular: 12.2.9
  • CDK/Material: 12.2.9

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
crisbetocommented, Oct 18, 2021

Yes, if you want free dragging (e.g. like a shortcut on your desktop), you should use cdkDrag without cdkDropList.

1reaction
crisbetocommented, Oct 18, 2021

how would one fire events on other elements? Just treat them as single item lists? I’m not sure what you mean by this. The events are fired by the CDK module, not the consumer.

As for terminology, the two main directives are:

  1. cdkDrag - an element that can be dragged. If it’s inside a cdkDropList, it’ll be treated as a part of the list, otherwise it can be dragged around freely.
  2. cdkDropList - a list that allows for cdkDrag items to be sorted. Lists can be connected in order to allow items to be transferred. cdkDropList is similar to jQuery UI sortable.

There are some other directives that supplement the two above. See the docs: https://material.angular.io/cdk/drag-drop/overview

Read more comments on GitHub >

github_iconTop Results From Across the Web

5 Things I wish I knew about the CDK's Drag & Drop
When I first implemented this by hand, I discovered that the native drag and drop capabilities move the image to a new layer...
Read more >
Drag and Drop | Angular Material
Emits when the user has moved a new drag item into this container. Emits when the user removes an item from the container...
Read more >
Angular CDK Drag and Drop: Cancel drag-action
If you want to disable dragging for a particular drag item, you can do so by setting the cdkDragDisabled input on a cdkDrag...
Read more >
Drag and drop multiple cdkDrag elements #13807 - GitHub
Select multiple cdkDrag elements e.g with a checkbox and drag ... dragging under the hood, bcs it require native mouse event and target....
Read more >
Drag-and-Drop Isn't a Drag with Angular Material CDK
From uploading files in Dropbox to sorting boards in Trello, drag-and-drop is an increasingly universal part of modern UIs.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found