Tree View
ProNewA hierarchy you can open, close and select from, with one Tab stop and full arrow-key navigation.
Installation
pnpm dlx shadcn@latest add @viewport/tree-view
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above comes with Truffle Pro.
Props
| Prop | Type | Default |
|---|---|---|
| nodes* | TreeNode[] | — |
| label* | stringAccessible name for the tree, e.g. "Folders". | — |
| selected | stringThe id of the selected node. | — |
| defaultSelected | string | — |
| onSelect | (id: string) => void | — |
| defaultExpanded | string[]Ids of the nodes that start open. | [] |
| className | string | — |
Accessibility
- The tree pattern: Up and Down move, Right opens or steps in, Left closes or steps out.
- Home, End and typing a letter jump between rows.
- Each row states its level, position and whether it is open.
- Respects prefers-reduced-motion.