Hierarchies for files, outlines and permissions: the selection is a ball that rolls along the guide lines, branches trace open and children cascade in.
Use it for hierarchies people browse and pick from: files, categories, permission scopes or a page outline. Supports single and multi selection, lazy-loaded branches and a checklist mode with partial folders.
When not to use
For flat app navigation use Sidebar. To pick one value from a long flat list use Combobox.
Use it for hierarchies people browse and pick from in a back-office app: folders and files in a
document manager, categories, org units, permission scopes, the outline of a long page. The selection
is one primary ball sitting on the guide lines: pick another row and it climbs its branch, steps out
at the junction under the parent's chevron, runs down the next guide and squashes against the row it
lands on. Opening a branch turns its chevron a quarter, traces the branch's guide line downward and
cascades the children in as the line reaches them. For flat navigation use the sidebar; for picking
one value from a long flat list use the combobox.
Or compose TreeItems, with asChild to render a row as your link:
import { TreeItem, TreeView } from "@/components/ui/tree-view";<TreeView aria-label="On this page" preset="outline" defaultSelected="invite"> <TreeItem value="members" label="Members and roles"> <TreeItem value="invite" asChild label={<a href="#invite">Invite members</a>} /> </TreeItem></TreeView>
expanded / selected / checked are controlled or uncontrolled (defaultExpanded,
defaultSelected, defaultChecked), with onExpandedChange, onSelectedChange and
onCheckedChange. multiple turns on file-explorer selection: Ctrl/⌘ click toggles, Shift click
and Shift + arrows select a range; the ball goes to the last item picked. Nodes marked lazy call
loadChildren(id) the first time they open and show two muted placeholder pills meanwhile. indent
sets the step per level (20 px by default, 16 or more keeps chevrons on the guides) and size the
row height (sm 28 px, md 32 px).
Three presets set the layout:
files (default): an icon per node (a folder is a tabbed tile whose front flap opens, a file is a
small sheet) and the meta on the right. Explorers.
outline: no icons, numbered levels ("2.1"); the guide lines are the only structure. Documents and
page outlines.
checklist: a checkbox per node. Checking a folder checks its whole branch, one stagger step per
child (the checkbox's own cascade); a folder with some checked leaves shows the indeterminate pill.
checked holds leaf ids; folders are derived. Clicking a row checks it (the chevron opens it).
Permissions and bulk pickers.
Open Settings › Members and choose Invite. Each person gets an email with a link that stays valid for seven days. Pick a role before you send: you can change it later.
The checklist preset in a role editor. Check Product to check its branch in a cascade; Finance is
partly checked; Payroll is disabled and never changes.
WAI-ARIA tree: role="tree" (label it with aria-label), items are treeitems with
aria-level, aria-setsize, aria-posinset, aria-expanded on branches, aria-selected, and
aria-checked (mixed for partial folders) in the checklist preset. Children sit in a
role="group". multiple sets aria-multiselectable.
One tab stop: roving tabIndex on the selected item (or its closed ancestor). The focus ring
(ring-ring/50, 3 px) is drawn on the row, never under the ball.
The selected row has its own tint, rim and weight, so the selection never relies on the ball. The
ball, the guide lines, the chevrons, the folder glyphs and the placeholder pills are aria-hidden.
A polite live region says "Finance expanded, 4 items" or "Finance collapsed" on toggle. Loading
branches have aria-busy.
Disabled items stay focusable with aria-disabled="true"; they are never selected, opened or
checked. Meta and numbers use muted-foreground, AA in both themes.
The ball still travels along the guide lines to the new row, in the short fade time and without
stretch or squash: a marker that moves is easier to follow than one that jumps. Guide lines appear
whole instead of tracing, children fade in together, chevrons and folder glyphs change in the same
fade and rows do not sink. At rest the tree is identical: rimmed selected row, the ball on its guide,
drawn lines.
Nothing runs at rest. A trip animates one transform on the ball (position on the mover, squash and
stretch on two nested layers); the route is a polyline measured from layout offsets when the
selection changes and again from one ResizeObserver while branches open or close above it. Opening a
branch animates its height (calm spring for branches over 8 children) and the opacity and transform of
its children. The tree is not virtualised: it renders at most 500 visible nodes. Our code, with the
shared ball and beats helpers, stays within the 12 kB gzip budget of the spec; third-party:
motion and @radix-ui/react-slot (about 1 kB gzip), both shared with other components; the
checklist preset reuses the MotionKit checkbox.
Technical sheet
Motion
calm
260 ms · bounce 0
lively
400 ms · bounce 0.3
playful
540 ms · bounce 0.45
Main spring of each temperament. Set it with the temperament prop or MotionKitProvider; the default is lively.
Size
Not measured yet · budget 6.0 kB gzip
Component and MotionKit helpers; excludes react, react-dom, motion, @radix-ui/react-slot.
Dependencies
@radix-ui/react-checkbox
@radix-ui/react-slot · peer
motion · peer
Triggers
click, press, a value change
Reduced motion
The ball still glides along the guide lines to the new row in the short fade time, without stretch or squash; guide lines appear whole and children fade in together.
Keyboard
Tab / Shift + Tab
Into the tree (lands on the selected item), then out
ArrowDown / ArrowUp
Next or previous visible item
ArrowRight
Opens a closed branch; on an open branch moves to its first child
ArrowLeft
Closes an open branch; otherwise moves to the parent
Home / End
First or last visible item
*
Opens every sibling branch of the focused item
Enter
Selects the item (the ball rolls to it), toggles a branch, follows a link row
Space
Selects the item (Ctrl/⌘ + Space toggles with multiple); checks it in the checklist preset
Shift + ArrowDown / ArrowUp
Extends the selection (multiple)
A-Z
Type-ahead: jumps to the next visible item starting with the typed text
Browsers
Last 2 versions of Chrome, Edge, Firefox and Safari (iOS 16.4+)