Tree View
Nested folders with the full ARIA tree keyboard model and typeahead.
- Category
- Navigation & layout
- Access
- Free with an account
- Source
- 184 lines · one file
The decision inside it
One tab stop, however big
Four hundred items should not mean four hundred Tab presses to get past them. Roving tabindex keeps exactly one item focusable.
When to use it
Use Tree View for nested items people expand and select: folders and files, categories, an org chart. Full keyboard support (arrows, Home, End, type-ahead).
Installation
How you get it
Paste this into Claude Code, Cursor, Codex or any coding agent. It installs the file and uses it as it is, instead of writing a new one.
Use Liro's Tree View for this.
Install it: npx shadcn@latest add @liro/tree
(the @liro registry is set up in components.json, with LIRO_KEY in .env.local)
Import it from @/components/ui/tree.
Do not rewrite or restyle it. Pass my data through its props
and keep its built-in states.For the full brief with every prop and the mistakes assistants usually make, use Copy prompt above. Free components install through the @liro registry with your CLI token: see the Namespaced tab.
Usage
import * as React from "react";
import { Tree, type TreeNode } from "@/components/ui/tree";
const items: TreeNode[] = [
{ id: "contracts", label: "Contracts", children: [{ id: "msa", label: "Vertically MSA.pdf" }, { id: "nda", label: "NDA.pdf" }] },
{ id: "invoices", label: "Invoices", children: [{ id: "oct", label: "October.csv" }] },
];
export function FileTree() {
const [selected, setSelected] = React.useState<string>();
return <Tree items={items} label="Files" selected={selected} onSelect={setSelected} defaultExpanded={["contracts"]} />;
}API reference
“Copy prompt” above puts a full brief on your clipboard, install command, dependencies, props, and the mistakes an assistant usually makes with this component.
Props
Read from the component’s own TypeScript interface when the site is built, so this table cannot drift from the file you install.
| Type | Notes | ||
|---|---|---|---|
items | TreeNode[] | Yes | – |
selected | string | No | – |
onSelect | (id: string, node: TreeNode) => void | No | – |
expanded | string[] | No | – |
defaultExpanded | string[] | No | – |
onExpandedChange | (ids: string[]) => void | No | – |
label | string | Yes | Accessible name. |
className | string | No | – |
Dependencies
npm packages
clsxlucide-reacttailwind-mergeLiro foundations, installed alongside it
liro-themeAccessibility
- Keyboard reachable throughout, in visual order
- Focus trapped in overlays, Escape closes them
- Focus returns to whatever opened it
- Live regions announce what changed, not that something did
- Honours prefers-reduced-motion
Responsive behavior
- Sizes to its container, not the viewport
- Usable from 320px up
- Pointer-based interaction, so trackpad and touch both work
- No hover-only affordances