Skip to content

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.

src/registry/ui/sortable-list.tsx/r/sortable-list.json

Installation

bash
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

tsx
import { SortableList } from "@/components/ui/sortable-list"

export function Example() {
  return (
    <SortableList />
  )
}

API reference

SortableList props
PropTypeDefault
itemsRows in their starting order. Defaults to a short sample task list.Item[]DEMO
onReorderCalled with the full list after every drag or keyboard move.(items: Item[]) => void-
classNamestring-

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

Keyboard interactions
KeyAction
TabMoves to the next row's drag handle.
ArrowUporArrowDownOn a handle, moves that row up or down one place. Focus stays on the handle.
HomeorEndOn 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 useReducedMotion branch 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

lucide-reactmotion

Built from

No other MiniDev files

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.

All kanban, timeline and workflow components