-
-
Notifications
You must be signed in to change notification settings - Fork 670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@dnd-kit/react source and target in sortable list always the same in onDragEnd handler #1564
Comments
I'm facing the same issue even in a Sortable list. |
This is because the DOM gets optimistically updated by @dnd-kit by default. If you would like to manage DOM and state manually, you can call <DragDropProvider
onDragOver={(event) => {
event.preventDefault();
}} |
Even if dnd-kit automatically handles the transition optimistically, how do we access the resulting index within One of the issues I continue to run into is that if I track the last dragged over item via |
There could potentially be a solution to this. If I clone the columns and items arrays, then have dnd-kit optimistically update the cloned arrays within |
You can read the index and group on start and end:
|
Makes sense @clauderic, thanks for clarifying, I'll post my updated implementation here shortly incase anyone else experiences something similar. One last thing though, what would the correct generics be for |
You can import the |
The |
It is exported: https://github.com/clauderic/dnd-kit/blob/experimental/packages/dom/src/sortable/index.ts#L3 You have to import it from |
Oh, it must only exported in the nightly builds, I have not merged Try installing one of the nightly builds, the latest one is 0.0.6-beta-20241204184550 |
Ah yes nice one, it's present in the nightly build 🚀 May also make sense to export SortableDraggable and SortableDroppable for people to use in their DragOperation generics on custom handlers. |
When composing a multiple sortable list and handling the
onDragEnd
event, bothoperation.source
andoperation.target
are always set to the currently dragged item when re-arranging the order of a parent list (i.e.: moving the position of a kanban column).When dragging the column, the
target
is only ever the correct one when you are dragging directly over the top of the target element itself.When
@dnd-kit/react
automatically re-positions other columns in the sortable list to "preview" where the dragged column will be dropped, it causes thetarget
to be subsequently set to the currently dragged column when there's no column "beneath" it besides the "ghost column".This makes it near enough impossible to trigger a change such as updating a column's position in an external DB:
Reproduction
I've created a reproduction of this issue by forking a minimal version of the multiple sortable lists example on CodeSandbox.
View the reproduction on CodeSandbox
The text was updated successfully, but these errors were encountered: