react-sortablejs icon indicating copy to clipboard operation
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.

Open tianfeng65 opened this issue 4 years ago • 2 comments

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 avatar Jan 15 '21 10:01 tianfeng65

@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 .

baquiax avatar Feb 18 '21 05:02 baquiax

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);
}}

baquiax avatar Feb 18 '21 15:02 baquiax