Back to elements
ElementData DisplayFree

Sortable List React component

A list people can put in their own order: drag a row by its handle and the others slide out of the way, or use the keyboard (Space to lift, arrows to move, Space to drop, Escape to undo), with live position numbers and optional remove buttons.

When to use the Sortable List component

Use Sortable List wherever order is the user's decision: agendas, playlists, priorities, menu items, form fields, steps in a flow. Dragging from the handle keeps the rest of the row free for scrolling on touch screens.

Save the new order from onValueChange; the component only reorders what you give it.

Installation

Add the Sortable List component to your project with the shadcn CLI. It lands in components/sortable-list.tsx as plain React + Tailwind CSS source you own and can edit.

Install
Copied!
npx shadcn@latest add https://reactframe.com/r/sortable-list.json

Or copy the source by hand and install its dependencies:

Install
Copied!
npm install motion clsx tailwind-merge

Props

<SortableList /> accepts 8 props, all optional.

  • items
    { id: string; title: string; meta?: string }[]
    Default: DEFAULT_ITEMS
  • value

    Controlled order.

    { id: string; title: string; meta?: string }[]
  • onValueChange
    (items: SortableItem[]) => void
  • showNumbers

    Show 1, 2, 3 ... in front of each row (they update as rows move).

    boolean
    Default: true
  • removable

    A remove button on each row.

    boolean
    Default: false
  • label
    string
    Default: "Agenda"
  • theme
    "dark" | "light"
    Default: "dark"
  • className
    string

FAQ

Can it be sorted without a mouse?
Yes. Tab to a row's handle, press Space to lift it, move it with the up and down arrows, and press Space to drop or Escape to put it back. Each step is announced to screen readers.
Why drag from a handle?
So the rest of the row can still be scrolled, selected or clicked, which matters most on phones.
Can people remove rows?
Set removable to add a × button on each row; the row collapses away and onValueChange receives the shorter list.

More Data Display components

Organization Chart
Free
Data View
Free
Transfer List
Free
Icon Box
Free
Tree Table
Free
Icon List
Free