dnd-kit sortable animation is triggering twice on DragEnd
Asked Answered
G

2

6

When I swap two distant items on a grid it 'redoes' the swap animation (going backwards then forwards again). It works fine when the items are very near as you can see in the following gif:

I've followed the Sortable docs but I can't figure out why it is redoing the animation. I just want to drop it on the grid cell and keep the old item on the position it already is, not doing the animation over again

Here's the link to the code sample

Garett answered 22/7, 2023 at 23:19 Comment(0)
G
12

Apparently I solved it setting animateLayoutChanges: () => false on the useSortable hook

Garett answered 23/7, 2023 at 1:23 Comment(1)
How to solve this for class based components?Ludwigshafen
P
2
  const { attributes, listeners, setNodeRef, transform, transition } =
    useSortable({
      id: image,
      transition: {
        duration: 500,
        easing: "cubic-bezier(0.25, 1, 0.5, 1)",
      },
    });

This is a better solution I found because animateLayoutChanges: () => false sets all the transition to false.

Peasecod answered 31/10, 2023 at 19:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.