Sortable

Reorders a list by dragging: rows of a group, table rows, images, tags and cards. The order changes on the drop.

Examples

Rows

Home screen

Today at a glance.
The latest ten.
New this week.
Sent on Mondays.

Rows with a handle

Contact details

Stacked rows

Questions

Different controls

Preferences

Table

ProductSKUStockPrice
Oak side tableOS-12014€129.00
Brass floor lampBF-2106€189.00
Linen armchairLA-3303€449.00
Wool rugWR-41022€249.00

Images

Blue picture
Green picture
Orange picture
Purple picture
Pink picture
Yellow picture

Tags

Design
Engineering
Marketing
Sales
Support
Finance
Legal
Operations

Cards

Revenue
€45,231
Orders
1,204
Customers
892
Refunds
12

API

PropTypeDefaultDescription
valueT[]—The list, in the order of the children
onChange(value: T[]) => void—Called with the new order after a drop
layout'list' | 'grid'listlist for rows one under another, grid for items that stand side by side
asElementTypedivElement to render, such as TableBody for table rows
disabledbooleanfalseTurns dragging off
handlesbooleantrue in a table, otherwise falseShows the grips of Sortable.Handle. A hidden grip still takes the keyboard, and the item drags from anywhere but a control
childrenReactNode—The items: one direct child per entry of value, keyed by the entry and not by its index

Sortable.Handle is the grip of an item. It renders a button, takes its props, and shows GripVertical unless it has children.

PropTypeDefaultDescription
aria-labelstringReorderName of the handle for assistive technology

The chip takes its text from data-sortable-label on the item, then from an element with that attribute or a label inside it, then from its first text. It shows the first img of the item.

Styling

Sortable reads these component tokens. Override them at any scope to restyle it:

  • --sortable-chip-max-width: chip max width (default 18rem)
  • --sortable-chip-radius: chip radius (default 14px)
  • --sortable-chip-image-size: picture in the chip (default 40px)
  • --sortable-chip-shadow: chip shadow
  • --sortable-chip-z-index: chip layer (default 100000)
  • --sortable-handle-size: handle size (default 32px)
  • --sortable-handle-icon-size: grip size (default 16px)
  • --sortable-handle-inset: handle offset from the edge of a row (default 8px)
  • --sortable-handle-color: grip color (default var(--color-text-tertiary))
  • --sortable-handle-color-hover: grip color on hover (default var(--color-text-secondary))
  • --sortable-line-size: line thickness (default 2px)
  • --sortable-line-color: line color (default var(--color-background-info-solid))
  • --sortable-slot-inset: slot inset in a list (default 8px)
  • --sortable-slot-radius: slot radius (default 12px)
  • --sortable-slot-background: slot under the pointer (default var(--color-background-info-soft))
  • --sortable-slot-background-away: slot once the pointer left it (default var(--color-surface-tertiary))