Skip to content

[bug] container sentinel moves with last item after sort #2441

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

Open
jbruce-JHA opened this issue Apr 24, 2025 · 0 comments
Open

[bug] container sentinel moves with last item after sort #2441

jbruce-JHA opened this issue Apr 24, 2025 · 0 comments

Comments

@jbruce-JHA
Copy link

jbruce-JHA commented Apr 24, 2025

When sorting list A.

A
...................
Apple
Banana
Cherry
"--container--"

B
..................
Cat
Dog
"--container--"

If I grab the second from the last item (Banana) and drag it to the last position (After Cherry), your "container" sentinel (I'm guessing) moves with the last item like below

Apple
Cherry
"--container--"
Banana

Now when I drag a new item from list B to the bottom of list A. the item is added above the contaner instead of being added to the end.

What I see:

Apple
Cherry
Cat
"--container--"
Banana

What I expect:

Apple
Cherry
Banana
Cat
"--container--"

It is my view that the container is incorrectly moving with the last item in the sort, then adding a new item via drag is inserting the drop in the incorrect location.

Versions
"sortablejs": "1.15.1",
"@types/sortablejs": "1.15.8",

Additional context

Adding this code to my 'onEnd' callback corrects the issue

    event.to.childNodes.forEach((value: ChildNode, key: number) => {

        // Find sentinel container
        if (value.nodeValue === "container") {

            // Remove sentinel container from current position and place it at the end.
            const container: ChildNode = event.to.removeChild(value);
            event.to.appendChild(container);
        }
    });
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

1 participant