Skip to content
Browse docs and components

Sortable List

sortable-list

A list you reorder by dragging a handle, or with the arrow keys once the handle has focus. The other rows move aside on a spring, the rest of each row stays free for text and links, and every keyboard move is announced with its new position.

Responsive

Install

$npxshadcnadd@forme/sortable-list

Adds the component, its registry dependencies, and the token stylesheet you import once.

Usage

import { SortableList } from "@/components/forme/sortable-list/sortable-list";

<SortableList
  label="Priorities"
  items={tasks}
  onReorder={setTasks}
  getId={(task) => task.id}
  getLabel={(task) => task.title}
  renderItem={(task) => <span>{task.title}</span>}
/>

When to use

Reach for it

  • Short lists whose order is the data: priorities, steps, a playlist.

Use something else

  • Long lists. Reordering hundreds of rows by drag is slower than a “move to” action.
  • Moving items between groups or columns — that is a board.

API reference

Read from the source, so it is the API of the file you install. A prop marked * is required.

SortableList

A list you reorder by dragging a handle — or, with the handle focused, with the arrow keys.

PropTypeDefaultDescription
items*readonly Item[]—
onReorder*(items: Item[]) => void—
getId*(item: Item) => string—
getLabel*(item: Item) => string—A short name for an item, used in the announcements: "Moved Design review to position 2".
renderItem*(item: Item) => ReactNode—
label*string—Accessible name for the list.
classNamestring—

Accessibility

  • Every row's handle works from the keyboard: focus it and press the up and down arrows.
  • Each keyboard move is announced with the item's new position.
  • The handle's label names the item and its position, read from getLabel.

Motion

  • The rows around the dragged one move aside on a spring; reduced motion makes the moves instant.

Responsive behaviour

  • Dragging starts only from the handle, so a touch scroll that begins on a row still scrolls the page.