Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting Issue #5

Open
mnofrizal opened this issue Apr 24, 2024 · 3 comments
Open

Sorting Issue #5

mnofrizal opened this issue Apr 24, 2024 · 3 comments

Comments

@mnofrizal
Copy link

I am putting the task on the very top of the list, so the overlay shows that it is going to be the very first task in this column, once I dropped the tasks, it goes at the very bottom of the column.
ezgif-6-fe182854cd

@Georgegriff
Copy link
Owner

See if you can fix it and share the solution, this is just a starter repo

@ahmedazizkhelifi
Copy link

TLDR;
@mnofrizal The issue is in this line:

return arrayMove(tasks, activeIndex, overIndex - 1);

If the overIndex is 0, so the to will be negative (-1) and arrayMove function will move the task in array.length + to position which is the last position.

You can find the arrayMove definition here : https://github.com/clauderic/dnd-kit/blob/master/packages/sortable/src/utilities/arrayMove.ts


The fix is to use the max of 0 and overIndex - 1

return arrayMove(tasks, activeIndex, Math.max(0, overIndex - 1));

@madebydor
Copy link

madebydor commented Oct 19, 2024

TLDR; @mnofrizal The issue is in this line:

return arrayMove(tasks, activeIndex, overIndex - 1);

If the overIndex is 0, so the to will be negative (-1) and arrayMove function will move the task in array.length + to position which is the last position.

You can find the arrayMove definition here : https://github.com/clauderic/dnd-kit/blob/master/packages/sortable/src/utilities/arrayMove.ts

The fix is to use the max of 0 and overIndex - 1

return arrayMove(tasks, activeIndex, Math.max(0, overIndex - 1));

I can verify the existence of this bug, as it happened to me as well.
I can also verify that @ahmedazizkhelifi solution fixed the bug.
Thank you @ahmedazizkhelifi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants