Skip to content
nexubDesign System
v11.9.0

Components · Data Display

Sortable

BetaAdded v6.5.0

A list people reorder by dragging or with Alt+Arrow keys on a handle.

import { Sortable } from '@nexub/react';
View as Markdown

Playground

Props

variant
layout
  • Revenue
  • Active users
  • Churn
  • Support tickets
TSX
<Sortable aria-label="Dashboard widgets" items={widgets} getId={(w) => w} getLabel={(w) => w} onReorder={setWidgets} className="w-full max-w-sm">…</Sortable>

Examples

Widget order

  • Revenue
  • Active users
  • Churn
  • Support tickets

Grid

Cards that wrap; the items have no id.

  • Harbour
  • Dunes
  • Forest
  • Glacier
  • Canyon
  • Meadow

Flat, locked and disabled

A dense list in a card: the first column is locked, and the switch turns editing off.

  • Name
  • Owner
  • Status
  • Due date
  • Budget

Groups

Move stories between the backlog and the sprint, by drag or Alt+ArrowLeft / Alt+ArrowRight.

Backlog

  • Export to CSV
  • Dark mode charts
  • SSO for teams

This sprint

  • Invoice reminders

States

    • Revenue
    • Active users
    • Churn
    • Support tickets
    default
    • Revenue
    • Active users
    • Churn
    • Support tickets
    disabled
    • Revenue
    • Active users
    • Churn
    • Support tickets
    variant="default"
    • Revenue
    • Active users
    • Churn
    • Support tickets
    variant="flat"

Props

Props
PropTypeDefaultDescription
itemsT[]—The list, in order. Not used with list.
getLabel((item: T) => string)—The name read in "Move ‹label›" and the move announcements. Defaults to String(item): pass it for objects.
getId((item: T) => string)—Stable key. Defaults to item.id, else a key kept per object, else the value itself (keep string values unique).
onReorder((items: T[]) => void)—Called with the new order; store it. Not used with list.
childrenrequired(item: T) => React.ReactNode—The item’s content; the handle sits before it.
aria-labelstring—Names the list. Inside a group it defaults to the list’s label.
layout'list' | 'grid''list'Default list. grid wraps items into cells (cards, images); Alt+Arrow keys move an item by one cell or row.
variant'default' | 'flat''default'Default default. flat drops the card chrome around items, for dense lists inside a card.
disabledboolean—Turns every handle off: nothing moves.
isLocked((item: T) => boolean)—Locked items show a lock, can’t be moved, and keep their index while others move around them, so nothing lands above a locked first item.
liststring''Inside Sortable.Group: which of its lists this renders (instead of items / onReorder).
Sortable.Group{ lists: { id, label, items }[]; onChange; getLabel; getId?; isLocked?; disabled? }—Owns several lists items move between; onChange gets every list after a move.
classNamestring—

Accessibility

Keyboard

  • Alt+ArrowUp / Alt+ArrowDown

    On a handle: moves the item (by a row in a grid); focus stays on its handle.

  • Alt+ArrowLeft / Alt+ArrowRight

    In a grid, moves the item by one cell; in a group, to the previous or next list. Mirrored in RTL.

Notes

  • Every handle is a button named "Move ‹label›", described by the key hint.

  • Moves are announced: "Alpha moved to position 3 of 5", or "Alpha moved to Sprint, position 1 of 2" across lists.

  • A locked item’s handle is disabled and named "‹label› is locked".

  • Dragging uses Pointer Events (mouse, pen, touch; Escape cancels), so there is no extra dependency. The settle animation is off under reduced motion.