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

Sortable animations don't work on latest release.

Open tonyjara opened this issue 5 years ago • 6 comments

Hi, I'm new to the library so excuse me if this is already being discussed. I couldn't find an open issue. Expected: https://codesandbox.io/s/mh95t?file=/package.json Actual behaviour: https://codesandbox.io/s/dnd-kit-sort-demo-forked-irhhk?file=/package.json

tonyjara avatar May 19 '21 00:05 tonyjara

id must be a string, not a number https://codesandbox.io/s/dnd-kit-sort-demo-forked-r3n3e

clauderic avatar May 19 '21 14:05 clauderic

@clauderic Could you put some some light why it changed to be a string? I think it's common to have numeric ids in apps. I'm debugging problems with upgrade in my app and I'm not sure if it is caused by this change or not.

morgoth avatar May 20 '21 16:05 morgoth

The documentation always explicitly stated that the id for draggable / droppable / sortable items had to be a string. It was a happy accident if it was working.

If your ids are numbers, just convert them to strings using toString:

[1,2,3].map(id => id.toString())

clauderic avatar May 20 '21 16:05 clauderic

@clauderic I'm going through documentation and I cannot find a mention about a hard requirement about string items. I can see it in examples as strings, but I guess it might be a common mistake made by end users, even more that in the examples there is an "id" name used, which most of the time is numeric in apps.

Is it making some big problems in the code to support numeric items?

morgoth avatar May 25 '21 16:05 morgoth

This is documented in multiple places:

Screen Shot 2021-05-25 at 12 07 46 PM

useDraggable

Screen Shot 2021-05-25 at 12 08 20 PM

useDroppable

Screen Shot 2021-05-25 at 12 08 51 PM

useSortable

It's probably not a major change to support this, you're welcome to open a PR if you want this to happen.

clauderic avatar May 25 '21 16:05 clauderic

String IDs are a huge mess for anyone whose data comes from a database. It means type conversions all over the place, and when I miss one (I have to convert in both directions assuming my application code that runs e.g. on drag end uses numeric IDs) I don't even get a useful error but just broken behavior.

ThiefMaster avatar Nov 03 '21 12:11 ThiefMaster