Skip to content

Content

Tree

Hierarchical tree with Tree.Item nodes and selection modes.

import { Tree } from '@var-ui/react';
  • src
    • App.tsx
  • README.md

Tree

Hierarchical expandable list with APG tree keyboard behavior. Compose nested Tree.Items or pass a recursive items array; control expand/selection with expanded / onExpandedChange and value / onValueChange (string ids; string[] with multiple).

Examples

Default

A small file tree with one folder expanded.

  • src
    • App.tsx
  • README.md
Demo.tsxTSX
import { Tree } from '@var-ui/react';

<Tree
  aria-label="Files"
  defaultExpanded={['src']}
  items={[{ id: 'src', label: 'src', children: [{ id: 'app', label: 'App.tsx' }] }]}
/>

Expanded selection

Seed nested expansion with defaultExpanded and highlight a leaf with defaultValue.

Selection is named like Select: passing value, defaultValue or onValueChange makes rows selectable (a row click selects it and sets aria-selected), and multiple allows more than one selected row, with value as string[]. Without any of them a row click toggles expansion.

  • src
    • components
      • Button.tsx
      • Input.tsx
    • App.tsx
  • README.md
Demo.tsxTSX
import { Tree } from '@var-ui/react';

<Tree
  aria-label="Project files"
  defaultExpanded={['src', 'components']}
  defaultValue="button"
  items={[
    {
      id: 'src',
      label: 'src',
      children: [
        {
          id: 'components',
          label: 'components',
          children: [{ id: 'button', label: 'Button.tsx' }],
        },
      ],
    },
  ]}
/>

Props

Accessibility

Root uses role="tree"; nodes are treeitem with aria-level, aria-expanded, and optional aria-selected. Provide an aria-label (or labelled-by) on the tree. Arrow keys move focus (roving tabindex); Left/Right collapse/expand; Space/Enter select when the rows are selectable.