dnd-kit icon indicating copy to clipboard operation
dnd-kit copied to clipboard

Issue with `useSortable` transforms being nulled for active item when dragged over a droppable outside the current SortableContext

Open lueenavarro opened this issue 3 years ago • 9 comments

I made this very simple example. https://codesandbox.io/s/dnd-kit-sortable-example-c1gtn.

I can't seem to drag the item outside of its current droppable. I am reading the documentation but I can't find what's wrong with the code

lueenavarro avatar May 15 '21 10:05 lueenavarro

Hi, I just tried the same thing yesterday, in fact according to this example: https://github.com/clauderic/dnd-kit/blob/6f762a4d8d0ea047c9e9ba324448d4aca258c6a0/stories/2%20-%20Presets/Sortable/MultipleContainers.tsx

You need to put the containerA item into the containerB items list while dragging.

For instance if you have:

itemsA = [..., ..., myActiveItem];
itemsB = [..., ..., ...];
itemsC = [..., ..., ...];

When you drag myActiveItem over containerB you must do:

setItemsA(itemsA.filter(p => p != myActiveItem));
setItemsB([...itemsB, myActiveItem]);

You will find the corresponding code under onDragOver here: https://github.com/clauderic/dnd-kit/blob/6f762a4d8d0ea047c9e9ba324448d4aca258c6a0/stories/2%20-%20Presets/Sortable/MultipleContainers.tsx#L189

RomaricMourgues avatar May 15 '21 11:05 RomaricMourgues

Thank you that worked! But I am still getting some blinking when moving an item between containers. I am not sure why.

https://user-images.githubusercontent.com/47080916/118366189-488ea680-b5d2-11eb-9696-f0133dff3a89.mp4

lueenavarro avatar May 15 '21 15:05 lueenavarro

Actually I have the same issue ! If you find why it happens please share :)

RomaricMourgues avatar May 15 '21 15:05 RomaricMourgues

Well I have it, you need to use the "createPortal" part, it will be used as the dragged component instead of the real component in containers. See this lines: https://github.com/clauderic/dnd-kit/blob/6f762a4d8d0ea047c9e9ba324448d4aca258c6a0/stories/2%20-%20Presets/Sortable/MultipleContainers.tsx#L327

RomaricMourgues avatar May 15 '21 15:05 RomaricMourgues

Thanks, I am still having trouble making it work but that makes sense to attach the draggable in the document body.

lueenavarro avatar May 15 '21 18:05 lueenavarro

I was able to make it work without createPortal but I did use DragOverlay. Here's an example of it: https://codesandbox.io/s/github/lueenavarro/dnd-kit-sortable

lueenavarro avatar May 16 '21 13:05 lueenavarro

This is technically a bug with useSortable, but indeed as mentioned by @lueenavarro, you can solve this by using DragOverlay for the time being until this is resolved

clauderic avatar May 20 '21 03:05 clauderic

Can somebody help me with a difficulty? I see these examples where you can sort items in a container and move itens from one container to another. And that it's fine! But in my case the containers needs to be sorted too. Just like Trello does. So the container can be sorted, the products inside container too and products from can be move from one container to other. Could someone give me some help? I'm completely lost!

william-hotmart avatar Aug 18 '21 15:08 william-hotmart

This is technically a bug with useSortable, but indeed as mentioned by @lueenavarro, you can solve this by using DragOverlay for the time being until this is resolved

@clauderic How complicated would the bug fix be? Is there a specific place in the code I could look?

KevinMusgrave avatar Aug 05 '22 23:08 KevinMusgrave

check id type. useSortable({ id }) and 《SortableContext items={ids} /》, id and ids type must be string.

bihtyu avatar Jun 20 '23 03:06 bihtyu