SortableJS / react-sortablejs

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

[bug] onMove return value not being respected #290

Open james-ritchey opened 5 months ago

james-ritchey commented 5 months ago

Describe the bug I have sortable items set up with different class names, including bookend-start and bookend-end, and the goal is to keep those items at the start and end of the list respectively. Using the onMove function we return the values shown in the docs to add the item before or after the related object, and while returning false works for cancelling the move, returning either 1 or -1 doesnt seem to have any affect, the dragged item is still dropped in the default direction.

To Reproduce Steps to reproduce the behavior:

  1. Create a sortable list with multiple items, including one with a class name like bookend-end
  2. Use the following function as the onMove for the sortable list
    const relatedClass = e.related.classList
    if (relatedClass.contains('sortable-fixed')) {
      return false
    }
    if (relatedClass.contains('bookend-start')) {
      return 1
    }
    if (relatedClass.contains('bookend-end')) {
      return -1
    } return true
    }
  3. Drag an item around the bookend, the item should still drop on either side, not just the side related to the returned integer

Expected behavior When we return 1 or -1 to the onMove, the dragged item be added only after or before the related item respectively.

Information

Versions - Look in your package.json for this information: "react-sortablejs": "^6.1.4", "react": "^18.2.0",