Xzero UI
Pro library

Tree view

Navigate nested folders and structured content.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/tree-view
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui/tree-view

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { TreeView, type TreeNode } from "@/components/xzero/tree-view/tree-view";

const files: TreeNode[] = [
  { id: "app", label: "app", children: [
    { id: "page", label: "page.tsx" },
    { id: "layout", label: "layout.tsx" },
  ] },
  { id: "readme", label: "README.md" },
];

export function Files() {
  return <TreeView nodes={files} defaultExpandedIds={["app"]} onSelect={node => open(node.id)} />;
}

API reference

TreeView

A keyboard navigable file tree with animated expand and a gliding selection.

PropTypeDefaultDescription
nodes (required){ id: string; label: string; children?: TreeNode[]; icon?: ReactNode }[]–Root nodes. Nodes with children are folders.
defaultExpandedIdsstring[][]Folders open on first render when uncontrolled.
expandedIdsstring[]–Controlled open folders.
onExpandedChange(expandedIds: string[]) => void–Called with the new open set.
onSelect(node: TreeNode) => void–Called when a row is clicked or activated.
aria-labelstring"File tree"Accessible name for the tree.

Keyboard interactions

KeysAction
ArrowDown / ArrowUpMoves to the next or previous visible row.
ArrowRightOpens a folder, or moves to its first child if open.
ArrowLeftCloses an open folder, or moves to the parent.
Home / EndMoves to the first or last visible row.
Enter / SpaceSelects the row and toggles a folder.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in tables

Guidance for AI tools

Tree view: Navigate nested folders and structured content. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components