Fix list widget reordering (#10654)

Fixes, but does not close #10651 - I will try adding some e2e tests for dragging (again).

The problem is, that removing/hiding element in the same frame as dragging starts, the drag is stopped immediately. It is presented here: https://jsfiddle.net/1g34jhe9/ (change `HIDE_IN_NEXT_FRAME` to compare).

In our case, the element removal was technically postponed to `nextTick`, but that is not enough after some version bump, as this tick occures after DOM recalculating, not necessarily after _rendering_ - changed it to setTimeout with proper comment.
This commit is contained in:
Adam Obuchowicz 2024-07-24 12:59:38 +02:00 committed by GitHub
parent e5b85bf16e
commit 82052e81aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -183,11 +183,13 @@ function onDragStart(event: DragEvent, index: number) {
const metaMime = encodeMetadataToMime(meta)
event.dataTransfer.setData(metaMime, '')
nextTick(() => {
// The code below will remove the item from list; because doing it in the same frame ends drag
// immediately, we need to put it in setTimeout (nextTick is not enough).
setTimeout(() => {
updateItemBounds()
draggedIndex.value = index
dropInfo.value = { meta, position: currentMousePos }
})
}, 0)
}
}