SortableJS / react-sortablejs

React bindings for SortableJS
http://sortablejs.github.io/react-sortablejs/
MIT License
2.06k stars 210 forks source link

[bug] Incorrect movement after resort items (with method sortable.sort) #215

Open alex14vdk opened 3 years ago

alex14vdk commented 3 years ago

Describe the bug I get incorrect behavior when i move items to neighbor block, after resort items with method sort()

var order = sortable.toArray();
sortable.sort(order.reverse(), true); // apply

To Reproduce Steps to reproduce the behavior:

  1. If we have two or more sortable blocks, and one of them has resort method before save like this

    const sortableOptions2 = {
    animation: 250,
    swapThreshold: 1,
    group: "shared",
    store: {
    set: function (sortable) {
      var order = sortable.toArray();
      sortable.sort(order.reverse(), true); //in my project other - more difficulty sort, "reverse()" here just for simply demostration
    }
    }
    };
  2. We shuffle items with dnd inside our block or move them to another block and put them back to first

  3. We need to make sure that our sortable.sort() has been done few times

  4. After that all, we try to move items to neighbor block, and usually we see that instead dragable item, we get absolutly incorrect item in neighbor block and our dragable item stayed at his place (in first block)

Expected behavior Of course i want to see correct item in neighbor block (dragable item). And i need to save resort items after every dragable.

Information Versions - Look in your package.json for this information: react-sortable = ^6.0.0 react = ^17.0.2

Additional context SANDBOX

I also tryed to do something like this without react-sortablejs (only with pure SortableJS), and everything was good as i remember