Reorder List

A list reordered by dragging a handle: the other rows make room as the dragged one passes, and buttons do the same from the keyboard.

Examples

Priorities

Drag a row by its handle, or use the arrows at the end of each row.

  • Ship the new billing pageAmara Okafor
  • Shorten onboarding to three stepsLéo Martin
  • Fix slow search on large workspacesSofia Brandt
  • Add CSV export to reportsKenji Mori

Drag the handle, use the move buttons, or press Space to pick up the row, the arrow keys to move it and Space to drop it.

Play queue

Rows can carry any content: here a length on the right, in tabular figures.

  • Low TideThe Marrow Lights3:42
  • Paper LanternsInes Valcourt4:05
  • North WindowHalvard Quartet5:18
  • Soft StaticJune Arden2:57
  • Harbour LightsOkoye & Lind3:30

Drag the handle, use the move buttons, or press Space to pick up the row, the arrow keys to move it and Space to drop it.

A short list with icon tiles, for a settings page.

Sidebar order

  • Inbox
  • Projects
  • Calendar
  • Reports

Drag the handle, use the move buttons, or press Space to pick up the row, the arrow keys to move it and Space to drop it.

Installation

npx shadcn@latest add https://ui.ndekocode.dev/r/motion-reorder-list.json

Component API

ReorderList

A controlled list: keep the items in state and pass the setter to onReorder.

PropTypeDefaultDescription
itemsT[]The items, in their current order.
onReorder(items: T[]) => voidCalled with the new order after a drag step, a button press or a key.
getKey(item: T) => stringA stable key for each item.
getLabel(item: T) => stringThe name read in the move buttons and in the announcements.
renderItem(item: T) => React.ReactNodeThe content of a row, between the handle and the move buttons.
aria-labelstringThe name of the list.
classNamestringClasses for the list.

Accessibility and motion

  • Three ways to move a row: drag the handle; press the move up or move down button; or focus the row, press Space to pick it up, the arrow keys to move it, Space to drop it and Escape to put it back.
  • Each move is announced with the new position, for example "Low Tide moved to position 2 of 5". A drag is announced once, when it ends.
  • The first row's move up button and the last row's move down button stay focusable but do nothing, so focus never jumps away after a move.
  • Rows settle on a spring with no bounce, and the dragged row lifts slightly. The list holds the row near its ends with a little give. With reduced motion, rows change place at once and the dragged row does not lift.

Credits

Inspired by the drag items of UI Layouts, rebuilt on the Reorder components of motion.