TreeView

Organism

Collapsible tree with keyboard navigation, selection, and aria-tree roles.

File tree

Preview
  • src
  • components
  • Button.tsx
  • Input.tsx
  • utils
  • cn.ts
  • public
  • logo.svg
  • package.json
Code
function Demo() {
  const [sel, setSel] = useState();
  return (
    <TreeView selectedId={sel} onSelect={setSel} label="Files"
      nodes={[
        { id: 'src', label: 'src', children: [
          { id: 'Button', label: 'Button.tsx' },
        ]},
      ]}
    />
  );
}

Navigation menu

Preview
  • Account
  • Profile
  • Password
  • Notifications
  • Workspace
  • General
  • Members
  • Billing
  • Integrations
Code
function Demo() {
  const [sel, setSel] = useState();
  return (
    <TreeView label="Settings navigation" selectedId={sel} onSelect={setSel}
      nodes={[
        { id: 'account', label: 'Account', children: [
          { id: 'profile', label: 'Profile' },
          { id: 'password', label: 'Password' },
        ]},
        { id: 'workspace', label: 'Workspace', children: [
          { id: 'general', label: 'General' },
          { id: 'billing', label: 'Billing' },
        ]},
        { id: 'integrations', label: 'Integrations' },
      ]}
    />
  );
}

Flat list

Preview
  • TypeScript
  • JavaScript
  • Python
  • Go
  • Rust
Code
function Demo() {
  const [sel, setSel] = useState('ts');
  return (
    <TreeView label="Language selector" selectedId={sel} onSelect={setSel}
      nodes={[
        { id: 'ts', label: 'TypeScript' },
        { id: 'js', label: 'JavaScript' },
        { id: 'py', label: 'Python' },
        { id: 'go', label: 'Go' },
      ]}
    />
  );
}

Multi-select + type-ahead

Preview
  • Documents
  • spec.md
  • roadmap.md
  • src
  • Button.tsx
  • Card.tsx
  • Drawer.tsx
  • TreeView.tsx
  • tests
  • unit
  • e2e
Code
function Demo() {
  const [ids, setIds] = useState<string[]>(['Card']);
  return (
    <TreeView
      label="Project files"
      selectionMode="multi"
      selectedIds={ids}
      onSelectionChange={setIds}
      nodes={[
        { id: 'docs', label: 'Documents', children: [
          { id: 'spec', label: 'spec.md' },
          { id: 'roadmap', label: 'roadmap.md' },
        ]},
        { id: 'src', label: 'src', children: [
          { id: 'Button', label: 'Button.tsx' },
          { id: 'Card', label: 'Card.tsx' },
          { id: 'Drawer', label: 'Drawer.tsx' },
          { id: 'TreeView', label: 'TreeView.tsx' },
        ]},
      ]}
    />
  );
}

// Try it:
//  - Cmd/Ctrl-click       → toggle individual rows
//  - Shift-click          → range-select between anchor and clicked row
//  - Type "tre"           → focus jumps to "TreeView.tsx"
//  - Cmd/Ctrl+A           → select all visible rows
//  - Arrow keys / Home/End / Space / Enter — full keyboard nav.
Sourcemodules/ui/TreeView/index.tsx