Examples

Approval queue

Preview
  1. Review invoice
  2. Confirm purchase order
  3. Notify supplier
Example.tsx
import { useState } from 'react';
import { SortableList } from '@reactloom/dnd';

export default function Example() {
  const [items, setItems] = useState([
    { id: 'review', label: 'Review invoice' },
    { id: 'confirm', label: 'Confirm purchase order' },
    { id: 'notify', label: 'Notify supplier' },
  ]);

  return <SortableList label="Approval steps" items={items} onChange={setItems} />;
}

Dashboard cards

Preview
  1. Usage
    69%
  2. Capacity
    128 GB
  3. Incidents
    2 open
  4. Availability
    99.8%
Example.tsx
import { useState } from 'react';
import { SortableGrid } from '@reactloom/dnd';

export default function Example() {
  const [items, setItems] = useState([
    { id: 'usage', label: 'Usage', metric: '69%' },
    { id: 'capacity', label: 'Capacity', metric: '128 GB' },
    { id: 'incidents', label: 'Incidents', metric: '2 open' },
    { id: 'availability', label: 'Availability', metric: '99.8%' },
  ]);

  return (
    <SortableGrid label="Dashboard card order" columns={2} items={items} onChange={setItems}
      renderItem={(item) => <><strong>{item.label}</strong><br />{item.metric}</>} />
  );
}

API reference

Sortable list and grid props
PropTypeDefault
labelrequired
Accessible name for the ordered collection.
string—
itemsrequired
Items with a unique, stable string id and a label.
readonly T[]—
onChangerequired
Receives the complete reordered collection. Update items to commit the move.
(items: T[]) => void—
renderItem
Render item details alongside the built-in controls.
(item: T) => ReactNode—
columns
SortableGrid only. Maximum columns. The collection uses fewer columns in narrower containers.
number3
disabled
Disable drag and all move controls.
booleanfalse
messages
Translate action and drop target labels and move announcements.
Partial<SortableMessages>—
className
Apply a class to the outer element.
string—

Customization

Set --pl-sortable-min on an ancestor to change a grid card’s minimum width. The default is 12rem. Use renderItem for the contents of each card.

Accessibility

Both layouts expose an ordered list. Dropping on another item moves the dragged item to that position. The move buttons follow reading order, including in a right-to-left grid. A live region announces the final position.

Keyboard interactions
KeyAction
Enter or Space on a move buttonMove one position earlier or later
Enter or Space on a drag handleEnter drag mode
Tab or Shift+Tab in drag modeChoose a drop position
Enter or Escape in drag modeDrop or cancel

Usage guidelines

Do

  • Use distinct item labels so move buttons and drag handles are easy to identify.
  • Keep item IDs stable across edits and reorders.

Don’t

  • Avoid sending reorder mutations during drag hover. Persist the new order from onChange.