Sortable List
Drag to reorder a list in React with Motion Reorder, plus Arrow key reordering from the handle and polite announcements of every move for screen readers.
Installation
npx shadcn@latest add @minidev/sortable-list
MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/sortable-list.json
Usage
import { SortableList } from "@/components/ui/sortable-list"
export function Example() {
return (
<SortableList />
)
}
API reference
When to use
Use it for short lists people order by hand: priorities, playlist tracks, checklist steps. Every row is rendered, so keep it to a few dozen items. Built on Motion's Reorder. KanbanBoard shows cards in columns but cannot drag them; for a fixed order use a plain list.
Keyboard: Arrow Up/Down move one place, Home/End move to the ends; focus stays on the moved handle. Pass a new items array (different ids or order) to reset the list from outside.
Keyboard interactions
| Key | Action |
|---|---|
| Tab | Moves to the next row's drag handle. |
| ArrowUporArrowDown | On a handle, moves that row up or down one place. Focus stays on the handle. |
| HomeorEnd | On a handle, moves that row to the top or bottom. |
Accessibility
- Each drag handle is a
<button>labelled with the row and its place, such as "Reorder Design review, position 2 of 5". - A polite live region announces each keyboard move, such as "Design review moved to position 1 of 5".
- Under reduced motion, the
useReducedMotionbranch turns off the layout animation, uses a zero-length transition and drops the 1.02 scale while dragging.
Frequently asked questions
How do I save the new order?
onReorder receives the full list after every keyboard move and every time rows swap during a drag, so it can fire several times per drag. Debounce the save, or save next.map((t) => t.id) when the order stops changing.
Is SortableList controlled?
It keeps its own order. A new items array resets it only when the ids or their order differ, so passing the onReorder result back in does not cause a loop.
Can rows show custom content?
Rows are { id, label, detail? }, with detail shown on the right in mono. For avatars, badges or buttons, copy the file and edit Row.
Dependencies
npm
Built from
Examples
Custom items
Each item needs a stable id and a label; detail is an optional right aligned note.
Read the new order
onReorder gets the full list after every drag or arrow key move, ready to persist.