react-sortablejs
react-sortablejs copied to clipboard
[bug] Whenever I click item, The order of the list does not change, and the setlist event will be triggered, which is not in line with the expectation.
Describe the bug
Whenever I click item, I just click. The order of the list does not change, and the setlist event will be triggered, which is not in line with the expectation.[bug]
Expected behavior Only trigger setList when the order changes
@tianfeng65 I think it's because the library change the list when you click on one of the children.
e.g If your list start like this
[{}, {}]
The library add some properties to your objects
[{"chosen":false,"selected":false},{"chosen":false,"selected":false}]
Then if you click on the first element of the grid, the underlying list will change meanwhile you are clicking the element
[{"chosen":true,"selected":false},{"chosen":false,"selected":false}]
Once you release the click you underlying list will change to:
[{"chosen":false,"selected":false},{"chosen":false,"selected":false}]
So this change of chosen is causing the update on the underlying list .
I way I solved this was handling the extra parameters that the setList callback returns
setList={(newItems, _, { dragging }) => {
// Dragging element is only present if you dragged an item, if it is a click it is null
if (!dragging) {
return;
}
setList(newItems);
}}