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' },
      ]}
    />
  );
}
Sourcemodules/ui/TreeView.tsx