SortableJS / Sortable

Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.
https://sortablejs.github.io/Sortable/
MIT License
29.09k stars 3.68k forks source link

[bug] `Sortable.sort()` with non-draggable items doesn't work properly #2262

Open aintyourcat opened 1 year ago

aintyourcat commented 1 year ago

Describe the bug

Whenever sort() called on a sortable element which has one or more non-draggable items, it will sort them weirdly.

To Reproduce Steps to reproduce the behavior:

  1. Go to this JS Bin.
  2. Try to move an item without removing any item first, it sorts the items properly.
  3. Remove an item or more, then move an item, it sorts the existing items unexpectedly.

Expected behavior

sort() should sort the existing items like how it sort items on a sortable element with no non-draggable items.

Information

sortablejs = 1.15.0

Additional context None.

Reproduction codesandbox: -

Merovex commented 1 year ago

I came to this issue due to a similar issue, but I was also dealing with a Svelte.

To fix my problem, I set forceFallback: true which counters the default HTML5 DnD behavior (which sets draggable=false. Because of Svelte's behavior, I had to use an afterUpdate() to set all the items in my list back to draggable=true

I'm thinking we're dealing with the same root cause.