Reorderable List
ProNewDrag a handle to reorder: the row follows the pointer while the others slide aside with transforms, and the DOM changes once on drop.
Installation
pnpm dlx shadcn@latest add @viewport/reorderable-list
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above comes with Truffle Pro.
Props
| Prop | Type | Default |
|---|---|---|
| items* | T[] | — |
| getId* | (item: T) => stringA stable id for each item. | — |
| getLabel* | (item: T) => stringThe item's name, used in announcements and on its drag handle. | — |
| onReorder* | (items: T[]) => voidReceives the items in their new order. | — |
| renderItem* | (item: T) => React.ReactNodeDraws the item's content. The drag handle is added before it. | — |
| label* | stringAccessible name for the list. | — |
| className | string | — |
| itemClassName | string | — |
Accessibility
- Every handle is a button named after its row.
- Up and Down on a handle move the row, and the new position is announced.
- Focus stays on the handle after a move.
- Respects prefers-reduced-motion.