All components

MotionReorder

Drag to reorder a list or a grid, with keyboard support.

WebReact NativeLists

Try it

Preparing the example…

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

PropTypeDefaultDescription
itemsreadonly T[]The items, when you control the order.
defaultItemsreadonly T[][]Starting items, when the component keeps the order.
onItemsChange(items, { reason, key }) => voidRuns with the new order and whether it came from a drag, a drop or the keyboard.
getKey(item) => string | numberitemReturns a unique key for an item. Defaults to the item itself.
renderItem(item, { index, dragging }) => ReactNodeitem.labelDraws 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.
columnsnumber3Columns in a grid.
gapnumber12Space between items in pixels.
disabledbooleanfalseTurns dragging off.
durationnumber260Milliseconds for items moving out of the way.
itemClassNamestringClass 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.

Web and React Native

onItemsChange(items, { reason }) tells you whether a change came from a drag, a drop or the keyboard.

On React Native the same props apply and reordering is also offered as accessibility actions.

Search

Type to search the documentation.