Description
Description
When moving an item from a root draggable to a nested draggable instance, the item appears in both places despite the data being updated correctly. This happens because the onRemove
handler re-inserts the item into the source list before checking pullMode
.
Current Behavior
- Move item from root draggable to nested draggable
- Item appears in both source and target lists
- Data updates correctly, but DOM doesn't reflect the change
Expected Behavior
When moving an item between draggable instances, the item should:
- Be removed from source list's DOM
- Appear only in target list
- Data and DOM should be in sync
Issue Location
In useDraggable.ts
, the onRemove
handler:
typescript
const defaultOptions = {
onRemove(evt: SortableEvent) {
const { from, item, oldIndex, oldDraggableIndex, pullMode, clone } = evt
insertNodeAt(from, item, oldIndex) // <-- This line causes the issue
if (pullMode === 'clone') {
removeNode(clone!)
return
}
// ... data update logic
}
}
The insertNodeAt(from, item, oldIndex)
call re-inserts the item into the source list before checking pullMode
, causing the item to remain in both places.
Reproduction
- Create two draggable instances (parent and nested)
- Configure with
group="items"
- Try to move item from parent to nested draggable
- Observe item appears in both lists
Environment
- vue-draggable-plus version: 6.0
- Vue version: 3.x