Skip to content

Early previewhamur is not on npm yet. The components are being built in the open, follow along on GitHub.

UIComponentsReact

Sortable List

A list whose items the user puts in order, with a handle to drag or pick up and buttons that move an item one place.

Built on the headless Sortable List.See its API in Docs

Rendered by React 19.3.1

sortable-list.tsx

Installation

npx shadcn@4.23.0 add https://hamur.dev/r/react/sortable-list.json

It also adds utils, button. The app needs its setup first: Installation.

Usage

Put a SortableListList inside SortableList, and give SortableList every item in value or defaultValue. The List renders one SortableListItem per item from a function child (Vue: the item slot; Svelte: the children snippet; Angular: @for over the List's items()), each holding a SortableListHandle and, if you want them, SortableListMoveButtons with to set to previous, next, first or last. A Handle and a MoveButton without content draw lucide's grip and chevrons, turned to the row when orientation is horizontal; the chevrons mirror in a right-to-left page. They are named by the headless part ("Reorder Apples", "Move Apples up"), so give them no visible text. Give the List a name (aria-label, aria-labelledby or a Field label). The keys, the drag, the announcements and the form value come from the headless Sortable List.

import {
  SortableList,
  SortableListHandle,
  SortableListItem,
  SortableListList,
  SortableListMoveButton,
} from '@/components/ui/sortable-list'

Examples

Default

Five fruits, each with a Handle and "previous" and "next" MoveButtons.

Its preview and code are at the top of the page.

The Item is drawn with the offset the headless List sets while it sorts, so the picked-up Item follows the pointer and the others shift to make room, and it takes a shadow and a ring while dragged and a 2 pixel outline while picked up by the keyboard. The Handle and the MoveButtons are 24 pixel ghost buttons (WCAG 2.5.8) with the focus ring (WCAG 2.4.7); one whose move does not apply stays focusable and is drawn at half opacity. A move is available without dragging (WCAG 2.5.7). This item takes Base UI's component ID as its slug and one name per Base UI part.

API reference

The styled parts pass every prop to the headless part they wrap and add classes. The props, data attributes and keyboard are on Sortable List's API reference.