clauderic / dnd-kit

The modern, lightweight, performant, accessible and extensible drag & drop toolkit for React.
http://dndkit.com
MIT License
13.31k stars 659 forks source link

how to copy item to other container? #1164

Open rmstsd opened 1 year ago

rmstsd commented 1 year ago

https://codesandbox.io/p/sandbox/determined-shaw-dggmrv

I want to copy the 'a' on the left side to the right side and generate a new id on the right side, and after copying it, I can't drag the left side the 'a'. It is very queer.

nicostombros commented 1 year ago

What do you mean by generating a new id on the right side?

ehrro commented 1 year ago

Do you need something like this? https://app.simplyfitness.com/workout-builder/new

rmstsd commented 1 year ago

if left side and right side have same id, when drap left item, right item will move together.

rmstsd commented 1 year ago

What do you mean by generating a new id on the right side?

Yes, this is the effect I want.

ehrro commented 1 year ago

I faced the same problem. You need to regenerate a new id for your sidebar items after each drag event.

I am passing a new state to my sidebar component to make it re-render and using uuid to generate new unique ID for my items.

setSidebarFieldsRegenKey(Date.now());

rmstsd commented 1 year ago

I faced the same problem. You need to regenerate a new id for your sidebar items after each drag event.

I am passing a new state to my sidebar component to make it re-render and using uuid to generate new unique ID for my items.

setSidebarFieldsRegenKey(Date.now());

Can you give an codesandbox example, please? Thank you!

ehrro commented 1 year ago

https://codesandbox.io/p/sandbox/wizardly-shaw-th5jt5

rmstsd commented 1 year ago

https://codesandbox.io/p/sandbox/wizardly-shaw-th5jt5

This is so cool, Thank you very much!

rmstsd commented 1 year ago

https://codesandbox.io/p/sandbox/wizardly-shaw-th5jt5

I found that the key code is here, and if this 'div' does not pass 'key' prop, there will be an exception.

ehrro commented 1 year ago

https://codesandbox.io/p/sandbox/wizardly-shaw-th5jt5

I found that the key code is here, and if this 'div' does not pass 'key' prop, there will be an exception.

Did you manage to implement DND the way you wanted?