Sortable
Reorder a list or grid by drag, keyboard and agents, built with definePrimitive over UI SDK's createReorder: a controlled string[] order, a draft while an item moves, an optional drag handle, checked items that move together, announcements with overridable labels, a FLIP slide on the motion tokens, and agent actions move(id, index) and reorder(order).
Example
Focus a layer, press Space, move it with the arrows.
Drag by the handle; Open stays a button.
Installation
lucide-reactUsage
Reorder a short list or grid by drag, keyboard and agents. For rows with links or buttons, use List sortable or a SortableHandle.
API reference
Sortable
| Prop | Type | Default |
|---|---|---|
childrenThe items, or a function of the order to render them in (the draft's while an item moves). | ReactNode | ((state: SortableState) => ReactNode) | – |
labels | Partial<SortableLabels> | – |
variant | "card" | "row" | "plain" | "card" |
Also takes ComponentProps except children.
SortableItem
Takes ComponentProps.
SortableHandle
| Prop | Type | Default |
|---|---|---|
labelThe item's name; the handle is called `labels.handle(label)`. | string | – |
labels | Partial<SortableLabels> | – |
value | string | – |
Also takes ComponentProps except value.
Other exports
sortablesortableLabelstransferLabelsuseFliptype SortableAutoScrolltype SortableOptionstype SortableReasontype SortableSelectReasontype SortableLabelstype TransferLabelstype SortableHandlePropstype SortableItemPropstype SortablePropstype SortableStatetype SortableVariantAccessibility
- Without a handle, a listbox of options with one tab stop: arrows move focus, Space or Enter lifts, the arrows, Home and End move, Space or Enter drops, Escape puts it back.
- With a handle, a list whose handles are one tab stop and the drag targets, so each item's own controls stay clickable.
- Every item or handle is described by the keyboard instructions, and each pickup, move and drop is announced; labels overrides the words.
- The neighbours slide into place with the panel motion token, and stay still under reduced motion.
Agent actions
Agents get move(id, index) and reorder(ids), with items named by itemLabel; wrong ids or indexes come back with what is allowed.
Runs agent.snapshot() from @ui-sdk/react/agent on the live preview above.