Data
Sortable list
A short list that the person puts in order, by dragging a handle or with the arrow keys.
Data
A short list that the person puts in order, by dragging a handle or with the arrow keys.
Change the props on the right. The list and its code follow.
import { Sortable, SortableHandle, SortableItem } from 'omuk-ui/sortable';
const [steps, setSteps] = useState(['Lint', 'Test', 'Build', 'Migrate']);
<Sortable
value={steps}
onValueChange={setSteps}
aria-label="Pipeline steps"
className="w-full max-w-sm gap-1"
>
{steps.map((step) => (
<SortableItem
key={step}
value={step}
label={step}
className="rounded-md p-2 inset-ring inset-ring-border"
>
<SortableHandle />
<span className="text-sm font-medium">{step}</span>
</SortableItem>
))}
</Sortable>Drag an item by its handle, or focus the handle, press Space, then press Up or Down. The items it passes slide aside; on the drop, onValueChange gets the new order.
Column order
An item is a row: put anything beside the handle. Here the order is a list of records, rebuilt from the values that onValueChange gives back.
Sortable is the list (a <ul>); SortableItem one item in it (an <li>); SortableHandle the button that moves it.
With the focus on a handle.