Tree
ProA nesting tree view for file explorers, category browsers and any hierarchy. Built on Radix Collapsible, with single selection, full keyboard navigation and CSS guide rails that trace every level.
Installation#
Usage#
The preview is yours to explore. Its code comes with a Pro license, paid once and used in every project.
Have a license? Unlock it here
A TreeItem with children is a branch (it renders a caret and a collapsible panel); without children it's a leaf. The value is the node's stable identity for selection and expansion. Pass label and icon so every row stays visually consistent, and nest items as children for depth.
Anatomy#
import { Tree, TreeItem } from "@/components/ui/tree"
<Tree>
<TreeItem value="branch" label="...">
<TreeItem value="leaf" label="..." />
</TreeItem>
</Tree>Selection#
Tree holds a single selection. Control it with value / onValueChange, or let it manage its own with defaultValue. Mark any node disabled to take it out of selection, expansion, and the keyboard order.
Trailing actions & guides#
The tree isn't only for files. Drop a count, a badge, or a menu in the actions slot, and turn off the indent rails with guides={false} when the icons alone carry the hierarchy.
Drag to reorder#
Pass onMove and every row becomes draggable. Drop near the top or bottom of a row to place a node before or after it, or onto the middle of a folder to drop it inside. The tree doesn't own your data, so it reports the move and you apply it; dropping a node into its own subtree is blocked, and Alt + ↑ / ↓ reorders siblings from the keyboard.
Keyboard#
Focus the tree and navigate without the mouse: ↑ / ↓ move between visible rows, → expands a collapsed branch then steps into it, ← collapses an open branch then steps out to its parent, Home / End jump to the first and last rows, and Enter / Space select (and toggle a branch).
API reference#
Tree
The role="tree" root (a <ul>). Owns single selection, the expanded set and the roving keyboard model. Forwards all native <ul> props; every part accepts className, merged last.
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | - | The selected node's value (controlled). |
| defaultValue | string | - | The initially selected node (uncontrolled). |
| onValueChange | (value: string) => void | - | Fires when a different node is selected. |
| expandedValues | string[] | - | The expanded branch values (controlled). |
| defaultExpandedValues | string[] | - | The initially expanded branches (uncontrolled). |
| onExpandedChange | (values: string[]) => void | - | Fires with the full expanded set whenever a branch toggles. |
| guides | boolean | true | Draws the vertical rails that trace each nesting level. |
| onMove | (move: TreeMoveEvent) => void | - | Enables drag to reorder and Alt + arrow sibling moves. Fires { value, target, position } with position one of "before" | "after" | "inside"; apply it to your own data. |
| CSS variable | Description |
|---|---|
| --tree-indent | The indent per level, set on the root (5.5 spacing steps). Override it to tighten or widen the ladder. |
TreeItem
A node (an <li> holding a role="treeitem" row). With nested TreeItem children it is a branch on a Radix Collapsible; without, a leaf. Forwards all native <li> props.
| Prop | Type | Default | Description |
|---|---|---|---|
| value* | string | - | Stable identity for selection, expansion and moves. |
| label | ReactNode | - | The row label, truncated to one line. |
| icon | ReactNode | - | Leading glyph, e.g. a folder or file icon. A bare icon is sized to 20px. |
| expandedIcon | ReactNode | icon | Leading glyph shown while the branch is open, e.g. FolderOpen. |
| actions | ReactNode | - | Trailing content such as a count badge or a row menu. |
| disabled | boolean | - | Removes the node from selection, expansion, focus and dragging. |
| children | ReactNode | - | Nested TreeItems. Their presence makes the node a branch. |
| Data attribute | Description |
|---|---|
| data-selected | "true" on the row of the selected node, else "false". |
| data-expanded | "true" on the row of an open branch, else "false". |
| data-branch | "true" when the node has children. |
| data-level | The row's depth, starting at 0. |
| data-value | The node's value, on the row. |
| data-dragging | Present on the row being dragged. |
| data-drop | before, after or inside on the row under a drag. |
| data-state | open or closed on a branch's nested group (Radix Collapsible). |
| CSS variable | Description |
|---|---|
| --tree-level | The depth, set inline on each row and group; drives the row inset and the guide rail position. |