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.No pointer needed. Tab to an item, press Space to grab it, move it with the arrow keys and press Space again to drop it. Escape puts the list back the way it was when you grabbed.
Reorder.Item is focusable (tabindex={0}). Space grabs and drops, arrows along the group's axis move, Escape restores the
order from the grab. Enter is left for taps.whileDrag state, so the lifted look you style for
pointer drags shows for keyboard grabs too.onReorder like a drag does, and the moved item keeps focus
and its grab while the list re-renders around it.Tab to an item, Space to grab, arrows to move