Reorder List
A list people can reorder by dragging or from the keyboard, with springy movement.
Overview
Reorder List lets people put a short list in their own order: priorities, steps, playlist tracks, or navigation items. Rows lift as they are picked up, and the others slide aside with a spring. Every row has a handle, which works with a pointer and with the keyboard, and each move is announced to screen readers.
The list is controlled. Pass the items in their current order and update them in onReorder.
Installation
Usage
import { ReorderList } from "@/components/animated/reorder-list"
const [tasks, setTasks] = useState(initialTasks)
<ReorderList
label="Priorities"
items={tasks}
onReorder={setTasks}
getKey={(task) => task.id}
getLabel={(task) => task.title}
renderItem={(task) => <span>{task.title}</span>}
/>renderItem draws the content of each row after the handle. It receives the item and { active, index }, so a row can change while it is being moved or show its position.
Drag the whole row
By default only the handle starts a pointer drag, which keeps links and buttons inside a row usable. Set handle={false} to let the whole row drag. Keyboard reordering always uses the handle.
Accessibility
Each handle is a button named "Reorder" followed by the item's label, and it describes the keys to use.
Focus stays on the handle while its row moves. Moving focus away drops the item where it is. Picking up, moving, dropping, and cancelling are announced in a polite live region, such as "Picked up Review billing changes. Position 2 of 5." Pass announcements and instructions to translate or reword them.
With reduced motion enabled, rows move straight to their new place and the picked-up row does not grow; its shadow still marks it.