Drag and drop
SortableList and SortableGrid
Let people change the order of approval steps, cards, or other items by dragging a handle or using the move buttons.
import '@reactloom/dnd/styles.css';
import { SortableList, SortableGrid } from '@reactloom/dnd';Examples
Approval queue
- Review invoice
- Confirm purchase order
- Notify supplier
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
- Usage
69% - Capacity
128 GB - Incidents
2 open - Availability
99.8%
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
| Prop | Type | Default |
|---|---|---|
labelrequiredAccessible name for the ordered collection. | string | — |
itemsrequiredItems with a unique, stable string id and a label. | readonly T[] | — |
onChangerequiredReceives the complete reordered collection. Update items to commit the move. | (items: T[]) => void | — |
renderItemRender item details alongside the built-in controls. | (item: T) => ReactNode | — |
columnsSortableGrid only. Maximum columns. The collection uses fewer columns in narrower containers. | number | 3 |
disabledDisable drag and all move controls. | boolean | false |
messagesTranslate action and drop target labels and move announcements. | Partial<SortableMessages> | — |
classNameApply 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.
| Key | Action |
|---|---|
| Enter or Space on a move button | Move one position earlier or later |
| Enter or Space on a drag handle | Enter drag mode |
| Tab or Shift+Tab in drag mode | Choose a drop position |
| Enter or Escape in drag mode | Drop 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.