All components
MotionReorder
Drag to reorder a list or a grid, with keyboard support.
WebReact NativeLists
Try it
Shortest usage
Playlist.jsx<MotionReorder
items={tracks}
onItemsChange={setTracks}
layout="list"
renderItem={(track) => track.title}
/>;
What it handles for you
- Other items move out of the way while you drag (
reorder="live") or once you drop (reorder="drop"). - List and grid layouts with
columns and gap. - Keyboard moves on the web, and accessibility actions on React Native.
- Controlled with
items and onItemsChange, or uncontrolled with defaultItems.
Use it for
- A playlist.
- A prioritized backlog.
- A photo grid.
Props
| Prop | Type | Default | Description |
|---|
items | readonly T[] | | The items, when you control the order. |
|---|
defaultItems | readonly T[] | [] | Starting items, when the component keeps the order. |
|---|
onItemsChange | (items, { reason, key }) => void | | Runs with the new order and whether it came from a drag, a drop or the keyboard. |
|---|
getKey | (item) => string | number | item | Returns a unique key for an item. Defaults to the item itself. |
|---|
renderItem | (item, { index, dragging }) => ReactNode | item.label | Draws an item; receives its index and whether it is being dragged. |
|---|
reorder | 'live' | 'drop' | 'live' | live moves other items while dragging; drop waits for the drop. |
|---|
layout | 'list' | 'grid' | 'grid' | list or grid. |
|---|
columns | number | 3 | Columns in a grid. |
|---|
gap | number | 12 | Space between items in pixels. |
|---|
disabled | boolean | false | Turns dragging off. |
|---|
duration | number | 260 | Milliseconds for items moving out of the way. |
|---|
itemClassName | string | | Class for each item element; itemStyle sets its inline style. |
|---|
Other props go to the rendered element, so className, style and event handlers work as usual.