Skip to content

Tree

Tree control for displaying hierarchical data, with expand/collapse support.

Basic Usage

Pass tree data with data. Each node can have label and children.

tsx
import { Tree } from '@airo-ui/react'

const treeData = [
  {
    label: 'Project',
    children: [
      {
        label: 'src',
        children: [
          { label: 'index.ts' },
          { label: 'App.tsx' },
          { label: 'styles.css' },
        ],
      },
      { label: 'package.json' },
      { label: 'README.md' },
    ],
  },
  { label: 'node_modules' },
]

function Demo() {
  return <Tree data={treeData} />
}

Node Click

onNodeClick returns the clicked node data and path.

tsx
<Tree
  data={treeData}
  onNodeClick={(node, path) => console.log(node.label, path)}
/>

API

Props

NameTypeDefaultDescription
dataTreeNodeData[]RequiredTree data
nodeKeystring'id'Node unique key field
onNodeClick(node: TreeNodeData, path: string) => void--Node click handler

TreeNodeData

PropertyTypeDescription
labelstringNode display text
childrenTreeNodeData[]Child nodes (optional)
[key: string]unknownAdditional custom properties

Interaction

  • Arrow icon rotates to indicate expand/collapse
  • Nodes with children show expand arrow
  • Nested level indentation
  • Hover highlight
  • Full ARIA tree role

MIT License