2

I'm trying to use the drag and drop feature provided by angular material to be able to move items from the Options list to either the Incude or Exclude list(whatever is enabled depending on the selected radio button in the Where to move group)

enter image description here

So far it works, but there's something weird when only the Include list is enabled.

If I try to move an item to the Exclude list, instead of item the being returned to the Options list, it is added to the Include list. It only works as expected if I drag the item without hovering over the Include list.

enter image description here

Is there any way to prevent the item from being dropped inside the Include list when what I wanted to do was to drop it inside another list?

BTW, this has nothing to do with the Exclude list being disabled. I already tested this having both lists enabled and always wins the first list I passed on my way to dropping the item in the desired list.

Here's a demo in stackblitz

eddy
  • 4,373
  • 16
  • 60
  • 94

1 Answers1

0

The drag and drop library saves the last active container and adds the draggable item to it when it's dropped. Which means if you drag an item over the Include list before you drop it on the invalid Exclude list, the last active container is still the Include list.

It's possible to use event.isPointerOverContainer in your drop method to check if it's dropped outside a dropcontainer. The disadvantage of this is the animation still returns the item back to the Include list first..

Felix
  • 1,337
  • 10
  • 10
  • So there's actually no possible solution ? – eddy Jul 13 '20 at 19:37
  • 1
    Not that i'm aware of. You could have a look at the CdkDragRelease event. It's fired before the animation so maybe you can change the drop container in there.. – Felix Jul 13 '20 at 21:22