svelte-sortable-list
svelte-sortable-list copied to clipboard
Unexpected sorting method
Hello! Great component, thanks for your work!
I could be wrong on this, but let me explain my doubt. Let's say I have a list of 3 elements
- Element 1
- Element 2
- Element 3
As soon as I click on Element 1 and I drag it down over Element 3, my expectation is that the Element 1 goes at third position (and that happens) however what usually happens in a sorting list is that Element 3 should shift up to the second position, instead of swapping its position with the first element
To be clear the list after the sort appears this way:
- Element 3
- Element 2
- Element 1
Though I would expect this:
- Element 2
- Element 3
- Element 1
Does this make sense? I guess it could be probably be achieved with #3
thank you! :)
I wanted the same behavior so I took #3 and made it into its own fork: https://github.com/Gjum/svelte-dragdrop-list
@Gjum Using your repo now! It's really nice. I hope your pull request gets accepted soon.
I think its best to make a prop called behaviour that chooses the function based on string "swap"/"sort" or may be a custom function!!
for
behaviour="swap"
1,2,3 to 3,2,1 (click:1, up:3)
const swapElements=()=>{
const temp=list[pick];
list.splice(pick,1,list[replace]);
list.splice(replace,1,temp);
list=list;
}
behaviour="reinsert"
1,2,3 to 2,3,1 (click:1, up:3)
const reinsertElements=()=>{
const temp=list[pick];
list.splice(pick,1);
list.splice(replace,0,temp);
list=list;
}