Overview
/docs
Installation
/docs/installation
Components
/docs/components
CLI
/docs/cli
aria-labeldisabledimport { useState } from "react"
import { Sortable, SortableHandle, SortableItem } from "@/components/ui/sortable"
const pages: Record<string, { title: string; path: string }> = {
overview: { title: "Overview", path: "/docs" },
install: { title: "Installation", path: "/docs/installation" },
components: { title: "Components", path: "/docs/components" },
cli: { title: "CLI", path: "/docs/cli" },
}
export function PageOrder() {
const [order, setOrder] = useState(["overview", "install", "components", "cli"])
return (
<Sortable aria-label="Pages" value={order} onValueChange={setOrder}>
{order.map((id) => (
<SortableItem key={id} id={id} label={pages[id].title}>
<SortableHandle />
<div className="min-w-0 flex-1">
<p className="text-sm font-medium">{pages[id].title}</p>
<p className="text-xs text-muted-foreground">{pages[id].path}</p>
</div>
</SortableItem>
))}
</Sortable>
)
}Usage
import { useState } from "react"
import { Sortable, SortableHandle, SortableItem } from "@/components/ui/sortable"
const pages: Record<string, string> = {
overview: "Overview",
install: "Installation",
components: "Components",
}
export function PageOrder() {
const [order, setOrder] = useState(["overview", "install", "components"])
return (
<Sortable aria-label="Pages" value={order} onValueChange={setOrder}>
{order.map((id) => (
<SortableItem key={id} id={id} label={pages[id]}>
<SortableHandle />
<span>{pages[id]}</span>
</SortableItem>
))}
</Sortable>
)
}Examples
Overview
/docs
Installation
/docs/installation
Components
/docs/components
CLI
/docs/cli
import { Sortable, SortableItem, SortableHandle } from '@/components/ui/sortable';
export function Example() {
const [order, setOrder] = useState(['overview', 'install', 'components']);
return (
<Sortable value={order} onValueChange={setOrder}>
{order.map((id) => (
<SortableItem key={id} id={id} label={pages[id].title}>
<SortableHandle />
<span className="min-w-0 flex-1 truncate text-sm">{pages[id].title}</span>
</SortableItem>
))}
</Sortable>
);
}- Overview1
- Installation2
- Components3
- CLI4
// Nothing to add. The handle is a real button, so the keyboard path comes with it:
// Space grabs, the arrows move, Space drops, Escape restores the pre-grab order, and
// Tab drops the row where it is. Every move goes out through a live region.
<SortableItem id={id} label={pages[id].title}>
<SortableHandle />
<span>{pages[id].title}</span>
</SortableItem>- Overview
- Installation
- Components
- CLI
// The handle is a button with your contents inside it. Where it sits in the row is
// a layout decision, not the component's.
<SortableItem id={id} label={pages[id].title}>
<span className="min-w-0 flex-1 truncate text-sm">{pages[id].title}</span>
<SortableHandle className="shrink-0 px-2 text-xs font-medium">Move</SortableHandle>
</SortableItem>Notes
Motion tier
Needs motion. add --all skips it; install with add --motion or by name.
Ids as order
value is a string[] of ids, not your objects. Keep the id-to-row lookup yourself.
Refusing a change
To refuse, do not apply next. details.cancel() undoes nothing itself; it marks the change refused, which tells an agent its move failed and suppresses the keyboard announcement.
When to use it
- Lists whose order is content: navigation, a playlist, a pinned set, form fields.
- Short lists visible whole; it does not handle dragging across a long scroll.
- Skip it for lists nobody reorders.
Behaviour
- Drags start only from the handle. Place it anywhere in the row.
- The lifted row scales slightly and takes a shadow.
- Displaced rows animate to their new positions.
API
details.reason says which. Required.value. Give the same string to React's key.Agent
Inside an AgentProvider, it appears in agent.snapshot() as list.
Reads
labelThe list's aria-label. Without one, the bridge names it list.
valueEvery row's label in order, joined with commas.
itemsEvery row's label, in order.
disabledTrue when the list is disabled.
Actions
move("Components", 1)Moves a row, by label then by id, to a position counted from 1. A miss lists the rows.
An agent's move runs through onValueChange like a drag. isAgentChange(details) is true for it; call details.cancel() and skip applying next to refuse, and the agent is told. A position outside the list fails; a disabled list refuses on its own.
await agent.act({
steps: [{ ref: "list", action: "move", args: ["CLI", 1] }],
})Accessibility
- Keeps
ulandlisemantics. - Handles are named after their row, as in
Reorder Installation;aria-pressedwhile lifted. - Grab, move, drop and cancel are announced assertively, with position.
- Escape while lifted cancels the reorder without closing an enclosing dialog.
- Reduced motion drops the lifted row's scale and shadow fade.