'Dnd-kit: active item loses order when dragged on Droppable
I'm facing a problem using @dnd-kit. The soring part works well (for example when I start dragging 1st element it obvioeulsy does sort), but when I reach a droppable element (green Thrash), the sorting breaks and the 1st element goes back.
You can see live demo here: link
Is there any way to fix this?
Solution 1:[1]
The problem was in handlers. When a dragged item reaches outside of the original drop area (a list), there is no more over-item under it. This is when the dragOver handler used to crash, since it relies on over.id internally
Solution: https://codesandbox.io/s/dndkit-grid-with-drag-handle-example-forked-w4j3sn
- Added checks for null and for id match
- Moved deletion logic to
dragEndhandler - Added state for dragged item reaching trash, so that list item can reflect it (becomes hidden)
- List item is hidden when dragged + new prop is true
- Moved Trash component out of original one, not critical tho
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | amankkg |
