loading code fetching the highlighted snippet
The motion.dev grocery list. Grab any item and drag it vertically — the dragged item pins under the cursor while its siblings spring out of the way, and releasing snaps it into its new slot.
Reorder.Group owns the order: it watches each drag and, when an item's
edge crosses the midpoint of a neighbor, calls onReorder with the
swapped array. Assigning that back to $state is the whole wiring.axis="y" locks item drags vertically. Items key on their own value in
the {#each} block — the same value passed to Reorder.Item's value prop.whileDrag passes straight through to the underlying motion component — the
lifted item scales up and gains a shadow while the gesture is active.Ten items in a 280px scroll container. Drag an item toward the top or bottom edge and hold — the container auto-scrolls beneath the held item so a single gesture can carry it the length of the list.
motion.div with layoutScroll, so
layout measurements are taken in the container's coordinate space and stay correct
at any scroll position.