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
Rows with a handle
Contact details
Stacked rows
Questions
Different controls
Preferences
Table
| Product | SKU | Stock | Price | |
|---|---|---|---|---|
| Oak side table | OS-120 | 14 | €129.00 | |
| Brass floor lamp | BF-210 | 6 | €189.00 | |
| Linen armchair | LA-330 | 3 | €449.00 | |
| Wool rug | WR-410 | 22 | €249.00 |
Images
Tags
Cards
Between lists
Today
Later
Done
Nothing here
API
| Prop | Type | Default | Description |
|---|---|---|---|
value | unknown[] | — | The list, in the order of the children. Bind with v-model:value |
layout | 'list' | 'grid' | list | list for rows one under another, grid for items that stand side by side |
as | string | Component | div | Element to render, such as TableBody for table rows |
disabled | boolean | false | Turns dragging off |
handles | boolean | true in a table, otherwise false | Shows the grips of SortableHandle. A hidden grip still takes the keyboard, and the item drags from anywhere but a control |
group | string | — | Lists of one group trade items, and a SortableTarget of that group takes them. Give each list a name |
name | string | — | 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.
| Prop | Type | Default | Description |
|---|---|---|---|
group | string | — | The group of the lists whose items it takes |
name | string | — | Names the target in move and hold |
as | string | Component | div | Element to render |
SortableHandle is the grip of an item. It renders a button, takes its attributes, and shows GripVertical unless its slot has content.
| Prop | Type | Default | Description |
|---|---|---|---|
aria-label | string | Reorder | Name 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 (default18rem)--sortable-chip-radius: chip radius (default14px)--sortable-chip-image-size: picture in the chip (default40px)--sortable-chip-shadow: chip shadow--sortable-chip-z-index: chip layer (default100000)--sortable-handle-size: handle size (default32px)--sortable-handle-icon-size: grip size (default16px)--sortable-handle-inset: handle offset from the edge of a row (default8px)--sortable-handle-color: grip color (defaultvar(--color-text-tertiary))--sortable-handle-color-hover: grip color on hover (defaultvar(--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.cssputs it last on a phone)--sortable-line-size: line thickness (default2px)--sortable-line-color: line color (defaultvar(--color-background-info-solid))--sortable-line-inset: line inset from the edges of a list (default16px)--sortable-slot-inset: slot inset in a list (default8px)--sortable-slot-radius: slot radius (default12px)--sortable-slot-background: slot under the pointer (defaultvar(--color-background-info-soft))--sortable-slot-background-away: slot once the pointer left it (defaultvar(--color-surface-tertiary))