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

Between lists

Today

Check the invoices
Call the supplier
Update the price list

Later

Plan the summer menu

Done

Nothing here

API

PropTypeDefaultDescription
valueunknown[]—The list, in the order of the children. Bind with v-model:value
layout'list' | 'grid'listlist for rows one under another, grid for items that stand side by side
asstring | ComponentdivElement to render, such as TableBody for table rows
disabledbooleanfalseTurns dragging off
handlesbooleantrue in a table, otherwise falseShows the grips of SortableHandle. A hidden grip still takes the keyboard, and the item drags from anywhere but a control
groupstring—Lists of one group trade items, and a SortableTarget of that group takes them. Give each list a name
namestring—Names the list in move

Events: update:value and change fire with the new order after a drop inside one list. move fires for every move with { item, from, fromIndex, to, toIndex }: out of a list the app updates both lists. hold fires with the name of a SortableTarget after a drag rests on it for half a second. The default slot holds the items: one direct child per entry of value, keyed by the entry and not by its index.

SortableTarget takes a drop from outside the lists, such as a row of a side navigation that stands for a list. A drop on it moves the item with toIndex undefined, to the end of that list. hold is the moment to open the list or go to it: the lists are measured again afterwards. It sets data-over while a drag is over it.

PropTypeDefaultDescription
groupstring—The group of the lists whose items it takes
namestring—Names the target in move and hold
asstring | ComponentdivElement to render

SortableHandle is the grip of an item. It renders a button, takes its attributes, and shows GripVertical unless its slot has content.

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, or an element with data-sortable-image, such as a hidden span with a cropped background.

An item with a ContextMenu takes one touch and hold for both: the hold opens the menu, and moving the finger on from there closes it and drags the item. A grip drags at once and opens no menu.

A control inside an item stops a drag. data-sortable-grab on a control that acts on a click lets a pull start one: the click still works when the pointer stays.

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-handle-order, --sortable-handle-margin-start, --sortable-handle-margin-end, --sortable-handle-field-margin-start: place of the handle in a row, the last one before a Field row (default first, with --sortable-handle-inset; touch.css puts it last on a phone)
  • --sortable-line-size: line thickness (default 2px)
  • --sortable-line-color: line color (default var(--color-background-info-solid))
  • --sortable-line-inset: line inset from the edges of a list (default 16px)
  • --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))