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.Drag one tile horizontally and vertically across wrapped rows. Every displaced tile springs into its new slot during the same continuous gesture.
axis="xy" clusters overlapping boxes into visual rows and chooses the nearest
row and horizontal insertion slot as the tile moves.values array; Reorder maps the visual wrapped
layout back to that logical order.This horizontal group omits axis and renders RTL. Geometry selects horizontal dragging automatically, and visual leftward movement advances the logical data order without reversing the array.
axis lets measured geometry select x, y, or xy; no orientation prop is needed for this row.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.