Create

General

Sortable

New
Copy page View as Markdown Open in ChatGPT Open in Claude

A list, row or grid whose items are reordered by dragging with the pointer, touch or the keyboard.

Usage#

app.component.ts
import { WDS_SORTABLE } from '@wds/angular/sortable';

Put wds-sortable-item elements in wds-sortable, each with a unique value. In plain HTML leave value on the list unset: it then moves the elements itself and wds-change carries the identifiers. In a framework bind value (the list of items) and set it again from wds-change, which fires live while dragging; item identifiers come from getItemValue (by default id). Lists of cards across several columns are in Kanban.

Examples#

Default#

A wds-sortable-item-handle (a grip icon when empty) limits dragging to itself, so the rest of the item can hold links and buttons. A copy of the item follows the pointer while the original keeps its place at half opacity.

High Medium High Low

Horizontal#

orientation="horizontal" lays the items out in a row; the left and right arrow keys move them. Without a handle the whole item is the handle.

Grid#

orientation="grid" fits as many columns as there is room for (--wds-sortable-item-min-width, here 10rem). A dragged tile takes the place of the tile nearest the pointer; from the keyboard the up and down arrows move it by a row.

Revenue $48.2k +12% this month
Active users 2,184 +5% this week
Orders 631 −3% this week
Refund rate 1.4% Stable
Open tickets 27 9 overdue
Uptime 99.98% Last 30 days

Placeholder overlay#

overlay="placeholder" drags a dashed box of the item’s size instead of its copy.

High Medium High Low

Disabled item#

disabled on an item keeps it from being dragged, but other items can still move past it. disabled on wds-sortable locks the whole list.

Pinned

Persist to a backend#

wds-commit fires once per finished drag (never during the live preview) with the new order and previousValue before it. Here the save fails about once in four tries and the list goes back to previousValue.

3:424:052:585:113:27

API References#

wds-sortable#

A list whose items are reordered by dragging: a column, a row or a grid. Each item is a wds-sortable-item; a wds-sortable-item-handle inside it limits dragging to the handle, otherwise the whole item is the handle. With value set (a property: the list of items), the list does not move elements itself: it fires wds-change with the new order, live while dragging, and you render it again. Without value it moves the elements and wds-change carries the identifiers. wds-commit fires once per finished drag, with the order before the drag, so a move can be saved and rolled back. The mouse starts a drag after 10px of movement, touch after holding for 250ms (moving earlier scrolls the page). From the keyboard Space or Enter picks the focused item up, the arrow keys move it, Space or Enter drops it and Escape cancels; each step is announced to screen readers.

Attributes

AttributeTypeDefaultDescription
orientationWdsSortableOrientation'vertical'vertical (a column), horizontal (a row) or grid (as many columns as fit). Also sets which arrow keys move an item.
overlayWdsSortableOverlay'clone'What follows the pointer while dragging: a copy of the item, or a dashed box of its size.
restore-on-cancel.restoreOnCancelbooleanfalseCancelling a drag (Escape) puts the items back in the order they had before the drag. Without it the moves stay and are committed.
disabledbooleanfalseNo item can be dragged.

Properties

PropertyDescription
valueT[] | undefinedThe items in display order. With it set the list is controlled: update it from wds-change. Without it the list reads and moves the elements.
getItemValue(item: T) => stringReturns the unique identifier of an item (the value of its wds-sortable-item). Defaults to id, then value, then the item itself.

Events

EventDescription
wds-changeCustomEvent<WdsSortableChangeDetail>The order changed: while dragging (live preview), on a cancel with restore-on-cancel.
wds-commitCustomEvent<WdsSortableCommitDetail>Once per finished drag that changed the order; carries the order before the drag.
wds-drag-startCustomEvent<WdsSortableDragDetail>A drag started.
wds-drag-endCustomEvent<WdsSortableDragDetail>A drag ended with a drop.
wds-drag-cancelCustomEvent<WdsSortableDragDetail>A drag was cancelled (Escape).

Slots

SlotDescription
(default)wds-sortable-item elements.

CSS custom properties

PropertyDescription
--wds-sortable-gapSpace between items (default 8px).
--wds-sortable-item-min-widthSmallest width of a grid column (default 8rem); the grid fits as many columns as there is room for.

wds-sortable-item#

An item of a wds-sortable. Without a wds-sortable-item-handle inside, the whole item is the handle: it is a button in the tab order, dragged with the pointer or picked up with Space or Enter.

Attributes

AttributeTypeDefaultDescription
valuestring''Unique identifier of the item in its list: what the list's getItemValue returns for it.
labelstring''Name of the item read by screen readers while dragging (defaults to value).
disabledbooleanfalseThe item cannot be dragged. Other items can still move past it.

Slots

SlotDescription
(default)Content of the item.

wds-sortable-item-handle#

The part of a wds-sortable-item that drags it. With a handle inside, only the handle starts a drag and takes keyboard focus; the rest of the item can hold links, inputs and buttons. Empty, it shows a grip icon; it can also wrap other content.

Attributes

AttributeTypeDefaultDescription
labelstring''Accessible name (defaults to „Move” with the item's name).

Slots

SlotDescription
(default)Content of the handle (defaults to a grip icon).

Accessibility#

Screen reader#

Each item (or its wds-sortable-item-handle) is a button in the tab order, with aria-description explaining the keys. A picked-up item has aria-pressed="true".

The handle is named „Move” with the item’s name; label on the handle overrides it.

Picking up, each move and the drop are announced in a live region with the position, e.g. „Glasshouse moved to position 2 of 5”. Give items a label so the announcements use their names instead of their identifiers. The copy that follows the pointer is aria-hidden.

Keyboard support#

KeyFunction
SpacePicks up the focused item; while dragging, drops it.
EnterPicks up the focused item; while dragging, drops it.
ArrowUpWhile dragging, moves the item one place back; in a grid, one row up.
ArrowDownWhile dragging, moves the item one place forward; in a grid, one row down.
ArrowLeftWhile dragging, moves the item one place back (forward in right-to-left layouts).
ArrowRightWhile dragging, moves the item one place forward (back in right-to-left layouts).
HomeWhile dragging, moves the item to the first place.
EndWhile dragging, moves the item to the last place.
EscapeCancels the drag; with restore-on-cancel the items go back to the order before it.
Footer