react-sortable-hoc icon indicating copy to clipboard operation
react-sortable-hoc copied to clipboard

disabled option still allows an element to move

Open oimos opened this issue 6 years ago • 3 comments

I see with disabled option the element is not draggable anymore but still moves when I drag another element over it. How can I make it "fixed" position and not let it change the order. In my case, I need to set the first item fixed, so it should not be draggable and unsortable.

oimos avatar Dec 17 '19 04:12 oimos

I tried to cancel the sort action by passing condition on onSortMove and return but did not work either. I need to a function like shouldCancelEnd

After a few hours investigation, I managed to add a function like below,

onSortEnd={({newIndex}) => {
         if (newIndex === 0) { // the first element is "unsortable"
             return;
         }
   }
}

But ideally I don't want the element move even though it goes back to the original position after mouse unholding

oimos avatar Dec 17 '19 06:12 oimos

I tried to cancel the sort action by passing condition on onSortMove and return but did not work either. I need to a function like shouldCancelEnd

After a few hours investigation, I managed to add a function like below,

onSortEnd={({newIndex}) => {
         if (newIndex === 0) { // the first element is "unsortable"
             return;
         }
   }
}

But ideally I don't want the element move even though it goes back to the original position after mouse unholding

I had a same issue, when first element should be "unsortable". In this case my workaround was

<SortableItem collection={index === 0 ? 1 : 0}/>

This only applies if "unsortable" item is a first item.

patrikw1 avatar Jan 27 '22 11:01 patrikw1

I tried to cancel the sort action by passing condition on onSortMove and return but did not work either. I need to a function like shouldCancelEnd After a few hours investigation, I managed to add a function like below,

onSortEnd={({newIndex}) => {
         if (newIndex === 0) { // the first element is "unsortable"
             return;
         }
   }
}

But ideally I don't want the element move even though it goes back to the original position after mouse unholding

I had a same issue, when first element should be "unsortable". In this case my workaround was

<SortableItem collection={index === 0 ? 1 : 0}/>

This only applies if "unsortable" item is a first item.

<SortableItem collection={index === 0 ? 1 : 0}/>

This will work for both starting and ending elements just need to pass collection={1}.

keshavashiya avatar Dec 27 '22 10:12 keshavashiya