Usage
Makes a collection's rows reorderable. On a touch screen a finger held still on a row's handle for a moment picks it up (a flick on the handle still scrolls): the row stays in its place, dimmed, while a copy of it follows the finger and an accent line marks where it would land; the other rows stay still, the page scrolls near its edges, and on release the rows rearrange. A mouse drags a handle at once the same way, and the rows take their places without motion; a cancelled drag puts everything back at once. Without a drag, the handle toggles reorder mode for its row (a click, Space or Enter): each arrow key moves the row a place at once, and Escape or another activation ends the mode, keeping the moves; screen readers hear each move with the row's place and neighbours, and a hint shows the moves and Done as buttons, for taps alone. The reorder code ships with this function: a collection without the prop loads none of it.
tsimport {createReorderable} from '@astryxdesign/core/reorderable'
Best practices
| Guidance | Practices |
|---|---|
| Do | Give each row a stable key from your data, a string or a number ( |
| Do | Use |
| Do | Offer reorder mode from your own UI too, such as a row's context menu, with |
| Don't | Use React's |
Parameters
| Param | Type | Description |
|---|---|---|
onReorderrequired | (move: {key: ; to: number}) => void | Called once per committed move (a drop, or each move in reorder mode) with the moved item's key and its index after the move, in the full order of the collection's items. Apply it by rendering the items in their new order. A cancelled move calls nothing. The latest function given is the one called, so the object may be made on every render. |
isReorderable | (key: ) => boolean | Whether the item with this key can move. An item it rejects shows no handle and cannot be picked up; one at either end of the collection also bounds the others, so nothing drops beyond it and a keyboard move into it is refused. Every item moves without it. |
Returns
| Field | Type | Description |
|---|---|---|
| reorderable | The collection's reorder behavior: pass it as |
Use with shadcn
Already using the shadcn registry workflow? Install the real Astryx package and a local public re-export. Component implementation source stays in Astryx.
This install URL expires with the draft preview.bashnpx shadcn@4.19.0 add https://astryx-jyoot9g02-fbopensource.vercel.app/shadcn/hooks/create-reorderable.json