# Tree View

URL: https://ark-ui.com/docs/react/components/tree-view
Markdown: https://ark-ui.com/docs/react/components/tree-view.md

A component that is used to show a tree hierarchy.

---

---
id: tree-view
title: Tree View
description: A component that is used to show a tree hierarchy.
---



## Anatomy



```tsx
<TreeView.Root>
  <TreeView.Label />
  <TreeView.Tree>
    <TreeView.NodeProvider>
      <TreeView.Branch>
        <TreeView.BranchControl>
          <TreeView.BranchIndicator />
          <TreeView.BranchText />
        </TreeView.BranchControl>
        <TreeView.BranchContent>
          <TreeView.BranchIndentGuide />
          <TreeView.Item>
            <TreeView.ItemText />
          </TreeView.Item>
        </TreeView.BranchContent>
      </TreeView.Branch>
    </TreeView.NodeProvider>
  </TreeView.Tree>
</TreeView.Root>
```

## Examples

```tsx
import { TreeView, createTreeCollection } from '@ark-ui/react/tree-view'
import { ChevronRightIcon, FileIcon, FolderIcon, FolderOpenIcon } from 'lucide-react'
import styles from 'styles/tree-view.module.css'

export const Basic = () => {
  return (
    <TreeView.Root className={styles.Root} collection={collection}>
      <TreeView.Label className={styles.Label}>Tree</TreeView.Label>
      <TreeView.Tree className={styles.Tree}>
        {collection.rootNode.children?.map((node, index) => (
          <TreeNode key={node.id} node={node} indexPath={[index]} />
        ))}
      </TreeView.Tree>
    </TreeView.Root>
  )
}

const TreeNode = (props: TreeView.NodeProviderProps<Node>) => {
  const { node, indexPath } = props
  return (
    <TreeView.NodeProvider key={node.id} node={node} indexPath={indexPath}>
      <TreeView.NodeContext>
        {(nodeState) =>
          nodeState.isBranch ? (
            <TreeView.NodeGroup className={styles.NodeGroup}>
              <TreeView.Node className={styles.Node}>
                <TreeView.Cell className={styles.Cell}>
                  <TreeView.NodeExpandTrigger className={styles.NodeExpandTrigger}>
                    <TreeView.NodeIndicator type="expanded" className={styles.NodeIndicator}>
                      <ChevronRightIcon />
                    </TreeView.NodeIndicator>
                  </TreeView.NodeExpandTrigger>
                  <TreeView.NodeText className={styles.NodeText}>
                    {nodeState.expanded ? <FolderOpenIcon /> : <FolderIcon />}
                    {node.name}
                  </TreeView.NodeText>
                </TreeView.Cell>
              </TreeView.Node>
              <TreeView.NodeGroupContent className={styles.NodeGroupContent}>
                <TreeView.IndentGuide className={styles.IndentGuide} />
                {node.children?.map((child, index) => (
                  <TreeNode key={child.id} node={child} indexPath={[...indexPath, index]} />
                ))}
              </TreeView.NodeGroupContent>
            </TreeView.NodeGroup>
          ) : (
            <TreeView.Node className={styles.Node}>
              <TreeView.Cell className={styles.Cell}>
                <TreeView.NodeText className={styles.NodeText}>
                  <FileIcon />
                  {node.name}
                </TreeView.NodeText>
              </TreeView.Cell>
            </TreeView.Node>
          )
        }
      </TreeView.NodeContext>
    </TreeView.NodeProvider>
  )
}

interface Node {
  id: string
  name: string
  children?: Node[] | undefined
}

const collection = createTreeCollection<Node>({
  nodeToValue: (node) => node.id,
  nodeToString: (node) => node.name,
  rootNode: {
    id: 'ROOT',
    name: '',
    children: [
      {
        id: 'node_modules',
        name: 'node_modules',
        children: [
          { id: 'node_modules/zag-js', name: 'zag-js' },
          { id: 'node_modules/pandacss', name: 'panda' },
          {
            id: 'node_modules/@types',
            name: '@types',
            children: [
              { id: 'node_modules/@types/react', name: 'react' },
              { id: 'node_modules/@types/react-dom', name: 'react-dom' },
            ],
          },
        ],
      },
      {
        id: 'src',
        name: 'src',
        children: [
          { id: 'src/app.tsx', name: 'app.tsx' },
          { id: 'src/index.ts', name: 'index.ts' },
        ],
      },
      { id: 'panda.config', name: 'panda.config.ts' },
      { id: 'package.json', name: 'package.json' },
      { id: 'renovate.json', name: 'renovate.json' },
      { id: 'readme.md', name: 'README.md' },
    ],
  },
})
```

### Controlled Expanded

Pass `expandedValue` and `onExpandedChange` to `TreeView.Root`.

```tsx
import { TreeView, createTreeCollection } from '@ark-ui/react/tree-view'
import { ChevronRightIcon, FileIcon, FolderIcon, FolderOpenIcon } from 'lucide-react'
import { useState } from 'react'
import styles from 'styles/tree-view.module.css'

export const ControlledExpanded = () => {
  const [expandedValue, setExpandedValue] = useState<string[]>(['node_modules'])
  return (
    <TreeView.Root
      className={styles.Root}
      collection={collection}
      expandedValue={expandedValue}
      onExpandedChange={({ expandedValue }) => setExpandedValue(expandedValue)}
    >
      <TreeView.Label className={styles.Label}>Tree</TreeView.Label>
      <TreeView.Tree className={styles.Tree}>
        {collection.rootNode.children?.map((node, index) => (
          <TreeNode key={node.id} node={node} indexPath={[index]} />
        ))}
      </TreeView.Tree>
    </TreeView.Root>
  )
}

const TreeNode = (props: TreeView.NodeProviderProps<Node>) => {
  const { node, indexPath } = props
  return (
    <TreeView.NodeProvider key={node.id} node={node} indexPath={indexPath}>
      <TreeView.NodeContext>
        {(nodeState) =>
          nodeState.isBranch ? (
            <TreeView.NodeGroup className={styles.NodeGroup}>
              <TreeView.Node className={styles.Node}>
                <TreeView.Cell className={styles.Cell}>
                  <TreeView.NodeExpandTrigger className={styles.NodeExpandTrigger}>
                    <TreeView.NodeIndicator type="expanded" className={styles.NodeIndicator}>
                      <ChevronRightIcon />
                    </TreeView.NodeIndicator>
                  </TreeView.NodeExpandTrigger>
                  <TreeView.NodeText className={styles.NodeText}>
                    {nodeState.expanded ? <FolderOpenIcon /> : <FolderIcon />}
                    {node.name}
                  </TreeView.NodeText>
                </TreeView.Cell>
              </TreeView.Node>
              <TreeView.NodeGroupContent className={styles.NodeGroupContent}>
                <TreeView.IndentGuide className={styles.IndentGuide} />
                {node.children?.map((child, index) => (
                  <TreeNode key={child.id} node={child} indexPath={[...indexPath, index]} />
                ))}
              </TreeView.NodeGroupContent>
            </TreeView.NodeGroup>
          ) : (
            <TreeView.Node className={styles.Node}>
              <TreeView.Cell className={styles.Cell}>
                <TreeView.NodeText className={styles.NodeText}>
                  <FileIcon />
                  {node.name}
                </TreeView.NodeText>
              </TreeView.Cell>
            </TreeView.Node>
          )
        }
      </TreeView.NodeContext>
    </TreeView.NodeProvider>
  )
}

interface Node {
  id: string
  name: string
  children?: Node[]
}

const collection = createTreeCollection<Node>({
  nodeToValue: (node) => node.id,
  nodeToString: (node) => node.name,
  rootNode: {
    id: 'ROOT',
    name: '',
    children: [
      {
        id: 'node_modules',
        name: 'node_modules',
        children: [
          { id: 'node_modules/zag-js', name: 'zag-js' },
          { id: 'node_modules/pandacss', name: 'panda' },
          {
            id: 'node_modules/@types',
            name: '@types',
            children: [
              { id: 'node_modules/@types/react', name: 'react' },
              { id: 'node_modules/@types/react-dom', name: 'react-dom' },
            ],
          },
        ],
      },
      {
        id: 'src',
        name: 'src',
        children: [
          { id: 'src/app.tsx', name: 'app.tsx' },
          { id: 'src/index.ts', name: 'index.ts' },
        ],
      },
      { id: 'panda.config', name: 'panda.config.ts' },
      { id: 'package.json', name: 'package.json' },
      { id: 'renovate.json', name: 'renovate.json' },
      { id: 'readme.md', name: 'README.md' },
    ],
  },
})
```

### Controlled Selection

Pass `selectedValue` and `onSelectionChange` to `TreeView.Root`.

```tsx
import { TreeView, createTreeCollection } from '@ark-ui/react/tree-view'
import { ChevronRightIcon, FileIcon, FolderIcon, FolderOpenIcon } from 'lucide-react'
import { useState } from 'react'
import styles from 'styles/tree-view.module.css'

export const ControlledSelected = () => {
  const [selectedValue, setSelectedValue] = useState<string[]>(['package.json'])
  return (
    <TreeView.Root
      className={styles.Root}
      collection={collection}
      selectedValue={selectedValue}
      onSelectionChange={({ selectedValue }) => setSelectedValue(selectedValue)}
    >
      <TreeView.Label className={styles.Label}>Tree</TreeView.Label>
      <TreeView.Tree className={styles.Tree}>
        {collection.rootNode.children?.map((node, index) => (
          <TreeNode key={node.id} node={node} indexPath={[index]} />
        ))}
      </TreeView.Tree>
    </TreeView.Root>
  )
}

const TreeNode = (props: TreeView.NodeProviderProps<Node>) => {
  const { node, indexPath } = props
  return (
    <TreeView.NodeProvider key={node.id} node={node} indexPath={indexPath}>
      <TreeView.NodeContext>
        {(nodeState) =>
          nodeState.isBranch ? (
            <TreeView.NodeGroup className={styles.NodeGroup}>
              <TreeView.Node className={styles.Node}>
                <TreeView.Cell className={styles.Cell}>
                  <TreeView.NodeExpandTrigger className={styles.NodeExpandTrigger}>
                    <TreeView.NodeIndicator type="expanded" className={styles.NodeIndicator}>
                      <ChevronRightIcon />
                    </TreeView.NodeIndicator>
                  </TreeView.NodeExpandTrigger>
                  <TreeView.NodeText className={styles.NodeText}>
                    {nodeState.expanded ? <FolderOpenIcon /> : <FolderIcon />}
                    {node.name}
                  </TreeView.NodeText>
                </TreeView.Cell>
              </TreeView.Node>
              <TreeView.NodeGroupContent className={styles.NodeGroupContent}>
                <TreeView.IndentGuide className={styles.IndentGuide} />
                {node.children?.map((child, index) => (
                  <TreeNode key={child.id} node={child} indexPath={[...indexPath, index]} />
                ))}
              </TreeView.NodeGroupContent>
            </TreeView.NodeGroup>
          ) : (
            <TreeView.Node className={styles.Node}>
              <TreeView.Cell className={styles.Cell}>
                <TreeView.NodeText className={styles.NodeText}>
                  <FileIcon />
                  {node.name}
                </TreeView.NodeText>
              </TreeView.Cell>
            </TreeView.Node>
          )
        }
      </TreeView.NodeContext>
    </TreeView.NodeProvider>
  )
}

interface Node {
  id: string
  name: string
  children?: Node[]
}

const collection = createTreeCollection<Node>({
  nodeToValue: (node) => node.id,
  nodeToString: (node) => node.name,
  rootNode: {
    id: 'ROOT',
    name: '',
    children: [
      {
        id: 'node_modules',
        name: 'node_modules',
        children: [
          { id: 'node_modules/zag-js', name: 'zag-js' },
          { id: 'node_modules/pandacss', name: 'panda' },
          {
            id: 'node_modules/@types',
            name: '@types',
            children: [
              { id: 'node_modules/@types/react', name: 'react' },
              { id: 'node_modules/@types/react-dom', name: 'react-dom' },
            ],
          },
        ],
      },
      {
        id: 'src',
        name: 'src',
        children: [
          { id: 'src/app.tsx', name: 'app.tsx' },
          { id: 'src/index.ts', name: 'index.ts' },
        ],
      },
      { id: 'panda.config', name: 'panda.config.ts' },
      { id: 'package.json', name: 'package.json' },
      { id: 'renovate.json', name: 'renovate.json' },
      { id: 'readme.md', name: 'README.md' },
    ],
  },
})
```

### Root Provider

Use `RootProvider` with the `useTreeView` hook to access the state and methods from outside the component.

```tsx
import { TreeView, createTreeCollection, useTreeView } from '@ark-ui/react/tree-view'
import { ChevronRightIcon, FileIcon, FolderIcon, FolderOpenIcon } from 'lucide-react'
import styles from 'styles/tree-view.module.css'

export const RootProvider = () => {
  const treeView = useTreeView({ collection })

  return (
    <div className="stack">
      <output>selected: {JSON.stringify(treeView.selectedValue)}</output>
      <TreeView.RootProvider className={styles.Root} value={treeView}>
        <TreeView.Label className={styles.Label}>Tree</TreeView.Label>
        <TreeView.Tree className={styles.Tree}>
          {collection.rootNode.children?.map((node, index) => (
            <TreeNode key={node.id} node={node} indexPath={[index]} />
          ))}
        </TreeView.Tree>
      </TreeView.RootProvider>
    </div>
  )
}

const TreeNode = (props: TreeView.NodeProviderProps<Node>) => {
  const { node, indexPath } = props
  return (
    <TreeView.NodeProvider key={node.id} node={node} indexPath={indexPath}>
      <TreeView.NodeContext>
        {(nodeState) =>
          nodeState.isBranch ? (
            <TreeView.NodeGroup className={styles.NodeGroup}>
              <TreeView.Node className={styles.Node}>
                <TreeView.Cell className={styles.Cell}>
                  <TreeView.NodeExpandTrigger className={styles.NodeExpandTrigger}>
                    <TreeView.NodeIndicator type="expanded" className={styles.NodeIndicator}>
                      <ChevronRightIcon />
                    </TreeView.NodeIndicator>
                  </TreeView.NodeExpandTrigger>
                  <TreeView.NodeText className={styles.NodeText}>
                    {nodeState.expanded ? <FolderOpenIcon /> : <FolderIcon />}
                    {node.name}
                  </TreeView.NodeText>
                </TreeView.Cell>
              </TreeView.Node>
              <TreeView.NodeGroupContent className={styles.NodeGroupContent}>
                <TreeView.IndentGuide className={styles.IndentGuide} />
                {node.children?.map((child, index) => (
                  <TreeNode key={child.id} node={child} indexPath={[...indexPath, index]} />
                ))}
              </TreeView.NodeGroupContent>
            </TreeView.NodeGroup>
          ) : (
            <TreeView.Node className={styles.Node}>
              <TreeView.Cell className={styles.Cell}>
                <TreeView.NodeText className={styles.NodeText}>
                  <FileIcon />
                  {node.name}
                </TreeView.NodeText>
              </TreeView.Cell>
            </TreeView.Node>
          )
        }
      </TreeView.NodeContext>
    </TreeView.NodeProvider>
  )
}

interface Node {
  id: string
  name: string
  children?: Node[] | undefined
}

const collection = createTreeCollection<Node>({
  nodeToValue: (node) => node.id,
  nodeToString: (node) => node.name,
  rootNode: {
    id: 'ROOT',
    name: '',
    children: [
      {
        id: 'node_modules',
        name: 'node_modules',
        children: [
          { id: 'node_modules/zag-js', name: 'zag-js' },
          { id: 'node_modules/pandacss', name: 'panda' },
          {
            id: 'node_modules/@types',
            name: '@types',
            children: [
              { id: 'node_modules/@types/react', name: 'react' },
              { id: 'node_modules/@types/react-dom', name: 'react-dom' },
            ],
          },
        ],
      },
      {
        id: 'src',
        name: 'src',
        children: [
          { id: 'src/app.tsx', name: 'app.tsx' },
          { id: 'src/index.ts', name: 'index.ts' },
        ],
      },
      { id: 'panda.config', name: 'panda.config.ts' },
      { id: 'package.json', name: 'package.json' },
      { id: 'renovate.json', name: 'renovate.json' },
      { id: 'readme.md', name: 'README.md' },
    ],
  },
})
```

### Lazy Loading

Load a node's children on demand to cut initial load time and memory use. Provide:

- `loadChildren`: loads the children of a node.
- `onLoadChildrenComplete`: called when children finish loading. Update the tree collection here.
- `childrenCount`: the number of children of a branch node.

```tsx
import { TreeView, createTreeCollection, useTreeViewNodeContext } from '@ark-ui/react/tree-view'
import { ChevronRightIcon, FileIcon, FolderIcon, FolderOpenIcon, LoaderIcon } from 'lucide-react'
import { useState } from 'react'
import styles from 'styles/tree-view.module.css'

// mock api result
const response: Record<string, Node[]> = {
  node_modules: [
    { id: 'zag-js', name: 'zag-js' },
    { id: 'pandacss', name: 'panda' },
    { id: '@types', name: '@types', childrenCount: 2 },
  ],
  'node_modules/@types': [
    { id: 'react', name: 'react' },
    { id: 'react-dom', name: 'react-dom' },
  ],
  src: [
    { id: 'app.tsx', name: 'app.tsx' },
    { id: 'index.ts', name: 'index.ts' },
  ],
}

// function to load children of a node
function loadChildren(details: TreeView.LoadChildrenDetails<Node>): Promise<Node[]> {
  const value = details.valuePath.join('/')
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(response[value] ?? [])
    }, 500)
  })
}

export const AsyncLoading = () => {
  const [collection, setCollection] = useState(initialCollection)
  return (
    <TreeView.Root
      className={styles.Root}
      collection={collection}
      loadChildren={loadChildren}
      onLoadChildrenComplete={(e) => setCollection(e.collection)}
    >
      <TreeView.Label className={styles.Label}>Tree</TreeView.Label>
      <TreeView.Tree className={styles.Tree}>
        {collection.rootNode.children?.map((node, index) => (
          <TreeNode key={node.id} node={node} indexPath={[index]} />
        ))}
      </TreeView.Tree>
    </TreeView.Root>
  )
}

function TreeBranchIcon() {
  const nodeState = useTreeViewNodeContext()
  if (nodeState.loading) return <LoaderIcon className={styles.Loader} />
  return nodeState.expanded ? <FolderOpenIcon /> : <FolderIcon />
}

const TreeNode = (props: TreeView.NodeProviderProps<Node>) => {
  const { node, indexPath } = props
  return (
    <TreeView.NodeProvider key={node.id} node={node} indexPath={indexPath}>
      {node.children || node.childrenCount ? (
        <TreeView.NodeGroup className={styles.NodeGroup}>
          <TreeView.Node className={styles.Node}>
            <TreeView.Cell className={styles.Cell}>
              <TreeView.NodeExpandTrigger className={styles.NodeExpandTrigger}>
                <TreeView.NodeIndicator type="expanded" className={styles.NodeIndicator}>
                  <ChevronRightIcon />
                </TreeView.NodeIndicator>
              </TreeView.NodeExpandTrigger>
              <TreeView.NodeText className={styles.NodeText}>
                <TreeBranchIcon /> {node.name}
              </TreeView.NodeText>
            </TreeView.Cell>
          </TreeView.Node>
          <TreeView.NodeGroupContent className={styles.NodeGroupContent}>
            <TreeView.IndentGuide className={styles.IndentGuide} />
            {node.children?.map((child, index) => (
              <TreeNode key={child.id} node={child} indexPath={[...indexPath, index]} />
            ))}
          </TreeView.NodeGroupContent>
        </TreeView.NodeGroup>
      ) : (
        <TreeView.Node className={styles.Node}>
          <TreeView.Cell className={styles.Cell}>
            <TreeView.NodeText className={styles.NodeText}>
              <FileIcon />
              {node.name}
            </TreeView.NodeText>
          </TreeView.Cell>
        </TreeView.Node>
      )}
    </TreeView.NodeProvider>
  )
}

interface Node {
  id: string
  name: string
  children?: Node[]
  childrenCount?: number
}

const initialCollection = createTreeCollection<Node>({
  nodeToValue: (node) => node.id,
  nodeToString: (node) => node.name,
  rootNode: {
    id: 'ROOT',
    name: '',
    children: [
      { id: 'node_modules', name: 'node_modules', childrenCount: 3 },
      { id: 'src', name: 'src', childrenCount: 2 },
      { id: 'panda.config', name: 'panda.config.ts' },
      { id: 'package.json', name: 'package.json' },
      { id: 'renovate.json', name: 'renovate.json' },
      { id: 'readme.md', name: 'README.md' },
    ],
  },
})
```

### Lazy Mount

Set `lazyMount` on `TreeView.Root` to render branch content only when it's expanded. This helps when content is large.

Add `unmountOnExit` to unmount content when a branch collapses. It re-renders the next time the branch expands.

```tsx
import { TreeView, createTreeCollection } from '@ark-ui/react/tree-view'
import { ChevronRightIcon, FileIcon, FolderIcon, FolderOpenIcon } from 'lucide-react'
import { useTreeViewNodeContext } from '../use-tree-view-node-context.ts'
import styles from 'styles/tree-view.module.css'

export const LazyMount = () => {
  return (
    <TreeView.Root className={styles.Root} collection={collection} lazyMount unmountOnExit>
      <TreeView.Label className={styles.Label}>Tree</TreeView.Label>
      <TreeView.Tree className={styles.Tree}>
        {collection.rootNode.children?.map((node, index) => (
          <TreeNode key={node.id} node={node} indexPath={[index]} />
        ))}
      </TreeView.Tree>
    </TreeView.Root>
  )
}

const TreeBranchIcon = () => {
  const { expanded } = useTreeViewNodeContext()
  return expanded ? <FolderOpenIcon /> : <FolderIcon />
}

const TreeNode = (props: TreeView.NodeProviderProps<Node>) => {
  const { node, indexPath } = props
  return (
    <TreeView.NodeProvider key={node.id} node={node} indexPath={indexPath}>
      {node.children ? (
        <TreeView.NodeGroup className={styles.NodeGroup}>
          <TreeView.Node className={styles.Node}>
            <TreeView.Cell className={styles.Cell}>
              <TreeView.NodeExpandTrigger className={styles.NodeExpandTrigger}>
                <TreeView.NodeIndicator type="expanded" className={styles.NodeIndicator}>
                  <ChevronRightIcon />
                </TreeView.NodeIndicator>
              </TreeView.NodeExpandTrigger>
              <TreeView.NodeText className={styles.NodeText}>
                <TreeBranchIcon /> {node.name}
              </TreeView.NodeText>
            </TreeView.Cell>
          </TreeView.Node>
          <TreeView.NodeGroupContent className={styles.NodeGroupContent}>
            <TreeView.IndentGuide className={styles.IndentGuide} />
            {node.children.map((child, index) => (
              <TreeNode key={child.id} node={child} indexPath={[...indexPath, index]} />
            ))}
          </TreeView.NodeGroupContent>
        </TreeView.NodeGroup>
      ) : (
        <TreeView.Node className={styles.Node}>
          <TreeView.Cell className={styles.Cell}>
            <TreeView.NodeText className={styles.NodeText}>
              <FileIcon />
              {node.name}
            </TreeView.NodeText>
          </TreeView.Cell>
        </TreeView.Node>
      )}
    </TreeView.NodeProvider>
  )
}

interface Node {
  id: string
  name: string
  children?: Node[] | undefined
}

const collection = createTreeCollection<Node>({
  nodeToValue: (node) => node.id,
  nodeToString: (node) => node.name,
  rootNode: {
    id: 'ROOT',
    name: '',
    children: [
      {
        id: 'node_modules',
        name: 'node_modules',
        children: [
          { id: 'node_modules/zag-js', name: 'zag-js' },
          { id: 'node_modules/pandacss', name: 'panda' },
          {
            id: 'node_modules/@types',
            name: '@types',
            children: [
              { id: 'node_modules/@types/react', name: 'react' },
              { id: 'node_modules/@types/react-dom', name: 'react-dom' },
            ],
          },
        ],
      },
      {
        id: 'src',
        name: 'src',
        children: [
          { id: 'src/app.tsx', name: 'app.tsx' },
          { id: 'src/index.ts', name: 'index.ts' },
        ],
      },
      { id: 'panda.config', name: 'panda.config.ts' },
      { id: 'package.json', name: 'package.json' },
      { id: 'renovate.json', name: 'renovate.json' },
      { id: 'readme.md', name: 'README.md' },
    ],
  },
})
```

### Filtering

Combine the collection's `filter` method with the `useFilter` hook to show only nodes that match a search query.

```tsx
import { useFilter } from '@ark-ui/react/locale'
import { TreeView, createTreeCollection, useTreeViewContext } from '@ark-ui/react/tree-view'
import { ChevronRightIcon, FileIcon, FolderIcon, FolderOpenIcon } from 'lucide-react'
import { useState } from 'react'
import styles from 'styles/tree-view.module.css'
import fieldStyles from 'styles/field.module.css'

export const Filtering = () => {
  const { contains } = useFilter({ sensitivity: 'base' })
  const [collection, setCollection] = useState(initialCollection)

  const filter = (value: string) => {
    const filtered =
      value.length > 0 ? initialCollection.filter((node) => contains(node.name, value)) : initialCollection
    setCollection(filtered)
  }

  return (
    <div className="stack" style={{ maxWidth: '20rem' }}>
      <input className={fieldStyles.Input} placeholder="Search" onChange={(e) => filter(e.target.value)} />
      <TreeView.Root className={styles.Root} collection={collection}>
        <TreeView.Tree className={styles.Tree}>
          {collection.rootNode.children?.map((node, index) => (
            <TreeNode key={node.id} node={node} indexPath={[index]} />
          ))}
        </TreeView.Tree>
      </TreeView.Root>
    </div>
  )
}

const TreeNode = (props: TreeView.NodeProviderProps<Node>) => {
  const { node, indexPath } = props
  const tree = useTreeViewContext()
  const nodeState = tree.getNodeState(props)
  return (
    <TreeView.NodeProvider key={node.id} node={node} indexPath={indexPath}>
      {nodeState.isBranch ? (
        <TreeView.NodeGroup className={styles.NodeGroup}>
          <TreeView.Node className={styles.Node}>
            <TreeView.Cell className={styles.Cell}>
              <TreeView.NodeExpandTrigger className={styles.NodeExpandTrigger}>
                <TreeView.NodeIndicator type="expanded" className={styles.NodeIndicator}>
                  <ChevronRightIcon />
                </TreeView.NodeIndicator>
              </TreeView.NodeExpandTrigger>
              <TreeView.NodeText className={styles.NodeText}>
                {nodeState.expanded ? <FolderOpenIcon /> : <FolderIcon />} {node.name}
              </TreeView.NodeText>
            </TreeView.Cell>
          </TreeView.Node>
          <TreeView.NodeGroupContent className={styles.NodeGroupContent}>
            <TreeView.IndentGuide className={styles.IndentGuide} />
            {node.children?.map((child, index) => (
              <TreeNode key={child.id} node={child} indexPath={[...indexPath, index]} />
            ))}
          </TreeView.NodeGroupContent>
        </TreeView.NodeGroup>
      ) : (
        <TreeView.Node className={styles.Node}>
          <TreeView.Cell className={styles.Cell}>
            <TreeView.NodeText className={styles.NodeText}>
              <FileIcon />
              {node.name}
            </TreeView.NodeText>
          </TreeView.Cell>
        </TreeView.Node>
      )}
    </TreeView.NodeProvider>
  )
}

interface Node {
  id: string
  name: string
  children?: Node[]
}

const initialCollection = createTreeCollection<Node>({
  nodeToValue: (node) => node.id,
  nodeToString: (node) => node.name,
  rootNode: {
    id: 'ROOT',
    name: '',
    children: [
      {
        id: 'node_modules',
        name: 'node_modules',
        children: [
          { id: 'node_modules/zag-js', name: 'zag-js' },
          { id: 'node_modules/pandacss', name: 'panda' },
          {
            id: 'node_modules/@types',
            name: '@types',
            children: [
              { id: 'node_modules/@types/react', name: 'react' },
              { id: 'node_modules/@types/react-dom', name: 'react-dom' },
            ],
          },
        ],
      },
      {
        id: 'src',
        name: 'src',
        children: [
          { id: 'src/app.tsx', name: 'app.tsx' },
          { id: 'src/index.ts', name: 'index.ts' },
        ],
      },
      { id: 'panda.config', name: 'panda.config.ts' },
      { id: 'package.json', name: 'package.json' },
      { id: 'renovate.json', name: 'renovate.json' },
      { id: 'readme.md', name: 'README.md' },
    ],
  },
})
```

### Links

Render tree items as links, for example in a docs site. Store a link hierarchy in the collection and use `asChild` to
render each item as an `<a>` with an `href`.

```tsx
import { TreeView, createTreeCollection } from '@ark-ui/react/tree-view'
import { ChevronRightIcon, ExternalLinkIcon, FileIcon } from 'lucide-react'
import styles from 'styles/tree-view.module.css'

export const Links = () => {
  return (
    <TreeView.Root className={styles.Root} collection={collection}>
      <TreeView.Label className={styles.Label}>Docs</TreeView.Label>
      <TreeView.Tree className={styles.Tree}>
        {collection.rootNode.children?.map((node, index) => (
          <TreeNode key={node.id} node={node} indexPath={[index]} />
        ))}
      </TreeView.Tree>
    </TreeView.Root>
  )
}

const TreeNode = (props: TreeView.NodeProviderProps<Node>) => {
  const { node, indexPath } = props
  return (
    <TreeView.NodeProvider key={node.id} node={node} indexPath={indexPath}>
      {node.children ? (
        <TreeView.NodeGroup className={styles.NodeGroup}>
          <TreeView.Node className={styles.Node}>
            <TreeView.Cell className={styles.Cell}>
              <TreeView.NodeExpandTrigger className={styles.NodeExpandTrigger}>
                <TreeView.NodeIndicator type="expanded" className={styles.NodeIndicator}>
                  <ChevronRightIcon />
                </TreeView.NodeIndicator>
              </TreeView.NodeExpandTrigger>
              <TreeView.NodeText className={styles.NodeText}>{node.name}</TreeView.NodeText>
            </TreeView.Cell>
          </TreeView.Node>
          <TreeView.NodeGroupContent className={styles.NodeGroupContent}>
            <TreeView.IndentGuide className={styles.IndentGuide} />
            {node.children.map((child, index) => (
              <TreeNode key={child.id} node={child} indexPath={[...indexPath, index]} />
            ))}
          </TreeView.NodeGroupContent>
        </TreeView.NodeGroup>
      ) : (
        <TreeView.Node className={styles.Node}>
          <TreeView.Cell
            className={styles.Cell}
            render={
              <a href={node.href}>
                <TreeView.NodeText className={styles.NodeText}>
                  <FileIcon />
                  {node.name}
                </TreeView.NodeText>
                {node.href?.startsWith('http') && <ExternalLinkIcon size={12} />}
              </a>
            }
          />
        </TreeView.Node>
      )}
    </TreeView.NodeProvider>
  )
}

interface Node {
  id: string
  name: string
  href?: string
  children?: Node[]
}

const collection = createTreeCollection<Node>({
  nodeToValue: (node) => node.id,
  nodeToString: (node) => node.name,
  rootNode: {
    id: 'ROOT',
    name: '',
    children: [
      {
        id: 'docs',
        name: 'Documentation',
        children: [
          { id: 'docs/getting-started', name: 'Getting Started', href: '/docs/getting-started' },
          { id: 'docs/installation', name: 'Installation', href: '/docs/installation' },
          {
            id: 'docs/components',
            name: 'Components',
            children: [
              { id: 'docs/components/accordion', name: 'Accordion', href: '/docs/components/accordion' },
              { id: 'docs/components/dialog', name: 'Dialog', href: '/docs/components/dialog' },
              { id: 'docs/components/menu', name: 'Menu', href: '/docs/components/menu' },
            ],
          },
        ],
      },
      {
        id: 'examples',
        name: 'Examples',
        children: [
          { id: 'examples/react', name: 'React Examples', href: '/examples/react' },
          { id: 'examples/vue', name: 'Vue Examples', href: '/examples/vue' },
          { id: 'examples/solid', name: 'Solid Examples', href: '/examples/solid' },
        ],
      },
      {
        id: 'external',
        name: 'External Links',
        children: [
          { id: 'external/github', name: 'GitHub Repository', href: 'https://github.com/chakra-ui/zag' },
          { id: 'external/npm', name: 'NPM Package', href: 'https://www.npmjs.com/package/@zag-js/core' },
          { id: 'external/docs', name: 'Official Docs', href: 'https://zagjs.com' },
        ],
      },
      { id: 'readme.md', name: 'README.md', href: '/readme' },
      { id: 'license', name: 'LICENSE', href: '/license' },
    ],
  },
})
```

### Virtualized

For trees with thousands of nodes, render only the visible rows with the [Virtualizer](/docs/utilities/virtualizer).

- Use `useTreeView` with `TreeView.RootProvider`.
- `getVisibleNodes()` returns the flat list of visible nodes. Keep the virtualizer's `count` in sync with it.
- Render `TreeView.Tree` as `ListVirtualizer.Root` and each `TreeView.Node` as `ListVirtualizer.Item`.
- Pass `scrollToIndexFn` to enable keyboard navigation.

```tsx
import { TreeView, createTreeCollection, useTreeView } from '@ark-ui/react/tree-view'
import { ListVirtualizer, useListVirtualizer } from '@ark-ui/react/virtualizer'
import { ChevronRightIcon, FileIcon, FolderIcon } from 'lucide-react'
import { useLayoutEffect } from 'react'
import button from 'styles/button.module.css'
import styles from 'styles/tree-view.module.css'

interface Node {
  id: string
  name: string
  children?: Node[]
}

function generateLargeTree(): Node {
  const folders: Node[] = []
  for (let i = 0; i < 50; i++) {
    const children: Node[] = []
    for (let j = 0; j < 20; j++) {
      children.push({ id: `folder-${i}/file-${i}-${j}.ts`, name: `file-${i}-${j}.ts` })
    }
    folders.push({ id: `folder-${i}`, name: `folder-${i}`, children })
  }
  return {
    id: 'ROOT',
    name: '',
    children: folders,
  }
}

const collection = createTreeCollection<Node>({
  nodeToValue: (node) => node.id,
  nodeToString: (node) => node.name,
  rootNode: generateLargeTree(),
})

const ROW_HEIGHT = 32

export const Virtualized = () => {
  const virtualizer = useListVirtualizer({
    count: 0,
    estimatedSize: () => ROW_HEIGHT,
    overscan: 10,
  })

  const tree = useTreeView({
    collection,
    scrollToIndexFn(details) {
      virtualizer.scrollToIndex(details.index, { align: 'auto' })
    },
  })

  const visibleNodes = tree.getVisibleNodes()
  const count = visibleNodes.length
  useLayoutEffect(() => {
    virtualizer.updateOptions({ count })
  }, [virtualizer, count])

  return (
    <TreeView.RootProvider className={styles.Root} value={tree}>
      <TreeView.Label className={styles.Label}>Virtualized Tree ({visibleNodes.length} visible nodes)</TreeView.Label>
      <div className="hstack">
        <button className={button.Root} onClick={() => tree.collapse()}>
          Collapse all
        </button>
        <button className={button.Root} onClick={() => tree.expand()}>
          Expand all
        </button>
      </div>
      <TreeView.Tree
        className={styles.Tree}
        style={{ height: 400 }}
        render={<ListVirtualizer.Root value={virtualizer} />}
      >
        <ListVirtualizer.Content>
          {virtualizer.getVirtualItems().map((virtualItem) => {
            const { node, indexPath } = visibleNodes[virtualItem.index]
            const nodeState = tree.getNodeState({ node, indexPath })

            return (
              <TreeView.NodeProvider key={node.id} node={node} indexPath={indexPath}>
                <TreeView.Node className={styles.Node} render={<ListVirtualizer.Item item={virtualItem} />}>
                  <TreeView.Cell className={styles.Cell} style={{ paddingLeft: nodeState.depth * 22 }}>
                    {nodeState.isBranch && (
                      <TreeView.NodeExpandTrigger className={styles.NodeExpandTrigger}>
                        <TreeView.NodeIndicator type="expanded" className={styles.NodeIndicator}>
                          <ChevronRightIcon />
                        </TreeView.NodeIndicator>
                      </TreeView.NodeExpandTrigger>
                    )}
                    <TreeView.NodeText className={styles.NodeText}>
                      {nodeState.isBranch ? <FolderIcon /> : <FileIcon />} {node.name}
                    </TreeView.NodeText>
                  </TreeView.Cell>
                </TreeView.Node>
              </TreeView.NodeProvider>
            )
          })}
        </ListVirtualizer.Content>
      </TreeView.Tree>
    </TreeView.RootProvider>
  )
}
```

### Checkbox Tree

Set `defaultCheckedValue` to enable checkbox selection. Checking a parent or child updates the related nodes.

```tsx
import { TreeView, createTreeCollection } from '@ark-ui/react/tree-view'
import { CheckIcon, ChevronRightIcon, MinusIcon } from 'lucide-react'
import styles from 'styles/tree-view.module.css'

export const CheckboxTree = () => {
  return (
    <TreeView.Root className={styles.Root} collection={collection} defaultCheckedValue={[]}>
      <TreeView.Label className={styles.Label}>Tree</TreeView.Label>
      <TreeView.Tree className={styles.Tree}>
        {collection.rootNode.children?.map((node, index) => (
          <TreeNode key={node.id} node={node} indexPath={[index]} />
        ))}
      </TreeView.Tree>
    </TreeView.Root>
  )
}

const TreeNodeCheckbox = (props: TreeView.NodeCheckboxProps) => {
  return (
    <TreeView.NodeCheckbox className={styles.NodeCheckbox} {...props}>
      <TreeView.NodeIndicator type="checked" className={styles.NodeIndicator}>
        <CheckIcon />
      </TreeView.NodeIndicator>
      <TreeView.NodeIndicator type="indeterminate" className={styles.NodeIndicator}>
        <MinusIcon />
      </TreeView.NodeIndicator>
    </TreeView.NodeCheckbox>
  )
}

const TreeNode = (props: TreeView.NodeProviderProps<Node>) => {
  const { node, indexPath } = props
  return (
    <TreeView.NodeProvider key={node.id} node={node} indexPath={indexPath}>
      {node.children ? (
        <TreeView.NodeGroup className={styles.NodeGroup}>
          <TreeView.Node className={styles.Node}>
            <TreeView.Cell className={styles.Cell}>
              <TreeView.NodeExpandTrigger className={styles.NodeExpandTrigger}>
                <TreeView.NodeIndicator type="expanded" className={styles.NodeIndicator}>
                  <ChevronRightIcon />
                </TreeView.NodeIndicator>
              </TreeView.NodeExpandTrigger>
              <TreeNodeCheckbox />
              <TreeView.NodeText className={styles.NodeText}>{node.name}</TreeView.NodeText>
            </TreeView.Cell>
          </TreeView.Node>
          <TreeView.NodeGroupContent className={styles.NodeGroupContent}>
            <TreeView.IndentGuide className={styles.IndentGuide} />
            {node.children.map((child, index) => (
              <TreeNode key={child.id} node={child} indexPath={[...indexPath, index]} />
            ))}
          </TreeView.NodeGroupContent>
        </TreeView.NodeGroup>
      ) : (
        <TreeView.Node className={styles.Node}>
          <TreeView.Cell className={styles.Cell}>
            <TreeNodeCheckbox />
            <TreeView.NodeText className={styles.NodeText}>{node.name}</TreeView.NodeText>
          </TreeView.Cell>
        </TreeView.Node>
      )}
    </TreeView.NodeProvider>
  )
}

interface Node {
  id: string
  name: string
  children?: Node[] | undefined
}

const collection = createTreeCollection<Node>({
  nodeToValue: (node) => node.id,
  nodeToString: (node) => node.name,
  rootNode: {
    id: 'ROOT',
    name: '',
    children: [
      {
        id: 'node_modules',
        name: 'node_modules',
        children: [
          { id: 'node_modules/zag-js', name: 'zag-js' },
          { id: 'node_modules/pandacss', name: 'panda' },
          {
            id: 'node_modules/@types',
            name: '@types',
            children: [
              { id: 'node_modules/@types/react', name: 'react' },
              { id: 'node_modules/@types/react-dom', name: 'react-dom' },
            ],
          },
        ],
      },
      {
        id: 'src',
        name: 'src',
        children: [
          { id: 'src/app.tsx', name: 'app.tsx' },
          { id: 'src/index.ts', name: 'index.ts' },
        ],
      },
      { id: 'panda.config', name: 'panda.config.ts' },
      { id: 'package.json', name: 'package.json' },
      { id: 'renovate.json', name: 'renovate.json' },
      { id: 'readme.md', name: 'README.md' },
    ],
  },
})
```

### Expand and Collapse All

Call `expand()` or `collapse()` from the tree view context to toggle all branches.

```tsx
import { TreeView, createTreeCollection, useTreeViewContext } from '@ark-ui/react/tree-view'
import { ChevronRightIcon, FileIcon, FolderIcon, FolderOpenIcon } from 'lucide-react'
import { useMemo } from 'react'
import button from 'styles/button.module.css'
import styles from 'styles/tree-view.module.css'

const ExpandCollapseButtons = () => {
  const tree = useTreeViewContext()
  const branchValues = useMemo(() => tree.collection.getBranchValues(), [tree.collection])
  const isAllExpanded = useMemo(
    () => branchValues.every((value) => tree.expandedValue.includes(value)),
    [tree.expandedValue, branchValues],
  )

  return (
    <div className="hstack">
      {isAllExpanded ? (
        <button className={button.Root} onClick={() => tree.collapse()}>
          Collapse all
        </button>
      ) : (
        <button className={button.Root} onClick={() => tree.expand()}>
          Expand all
        </button>
      )}
    </div>
  )
}

export const ExpandCollapseAll = () => {
  return (
    <TreeView.Root className={styles.Root} collection={collection} data-animate="false">
      <ExpandCollapseButtons />
      <TreeView.Tree className={styles.Tree}>
        {collection.rootNode.children?.map((node, index) => (
          <TreeNode key={node.id} node={node} indexPath={[index]} />
        ))}
      </TreeView.Tree>
    </TreeView.Root>
  )
}

const TreeNode = (props: TreeView.NodeProviderProps<Node>) => {
  const { node, indexPath } = props
  return (
    <TreeView.NodeProvider key={node.id} node={node} indexPath={indexPath}>
      <TreeView.NodeContext>
        {(nodeState) =>
          nodeState.isBranch ? (
            <TreeView.NodeGroup className={styles.NodeGroup}>
              <TreeView.Node className={styles.Node}>
                <TreeView.Cell className={styles.Cell}>
                  <TreeView.NodeExpandTrigger className={styles.NodeExpandTrigger}>
                    <TreeView.NodeIndicator type="expanded" className={styles.NodeIndicator}>
                      <ChevronRightIcon />
                    </TreeView.NodeIndicator>
                  </TreeView.NodeExpandTrigger>
                  <TreeView.NodeText className={styles.NodeText}>
                    {nodeState.expanded ? <FolderOpenIcon /> : <FolderIcon />}
                    {node.name}
                  </TreeView.NodeText>
                </TreeView.Cell>
              </TreeView.Node>
              <TreeView.NodeGroupContent className={styles.NodeGroupContent}>
                <TreeView.IndentGuide className={styles.IndentGuide} />
                {node.children?.map((child, index) => (
                  <TreeNode key={child.id} node={child} indexPath={[...indexPath, index]} />
                ))}
              </TreeView.NodeGroupContent>
            </TreeView.NodeGroup>
          ) : (
            <TreeView.Node className={styles.Node}>
              <TreeView.Cell className={styles.Cell}>
                <TreeView.NodeText className={styles.NodeText}>
                  <FileIcon />
                  {node.name}
                </TreeView.NodeText>
              </TreeView.Cell>
            </TreeView.Node>
          )
        }
      </TreeView.NodeContext>
    </TreeView.NodeProvider>
  )
}

interface Node {
  id: string
  name: string
  children?: Node[]
}

const collection = createTreeCollection<Node>({
  nodeToValue: (node) => node.id,
  nodeToString: (node) => node.name,
  rootNode: {
    id: 'ROOT',
    name: '',
    children: [
      {
        id: 'node_modules',
        name: 'node_modules',
        children: [
          { id: 'node_modules/zag-js', name: 'zag-js' },
          { id: 'node_modules/pandacss', name: 'panda' },
          {
            id: 'node_modules/@types',
            name: '@types',
            children: [
              { id: 'node_modules/@types/react', name: 'react' },
              { id: 'node_modules/@types/react-dom', name: 'react-dom' },
            ],
          },
        ],
      },
      {
        id: 'src',
        name: 'src',
        children: [
          { id: 'src/app.tsx', name: 'app.tsx' },
          { id: 'src/index.ts', name: 'index.ts' },
        ],
      },
      { id: 'panda.config', name: 'panda.config.ts' },
      { id: 'package.json', name: 'package.json' },
      { id: 'renovate.json', name: 'renovate.json' },
      { id: 'readme.md', name: 'README.md' },
    ],
  },
})
```

### Mutation

Use the collection's `remove()` and `replace()` methods to add and remove nodes, for example in a file explorer.

```tsx
import { TreeView, createTreeCollection, useTreeViewContext } from '@ark-ui/react/tree-view'
import { ChevronRightIcon, PlusIcon, TrashIcon } from 'lucide-react'
import { useState } from 'react'
import styles from 'styles/tree-view.module.css'

export const Mutation = () => {
  const [collection, setCollection] = useState(initialCollection)

  const removeNode = (props: TreeNodeProps) => {
    setCollection(collection.remove([props.indexPath]))
  }

  const addNode = (props: TreeNodeProps) => {
    const { node, indexPath } = props
    if (!collection.isBranchNode(node)) return
    const children = [{ id: `untitled-${Date.now()}`, name: 'untitled.tsx' }, ...(node.children || [])]
    setCollection(collection.replace(indexPath, { ...node, children }))
  }

  return (
    <TreeView.Root className={styles.Root} collection={collection}>
      <TreeView.Tree className={styles.Tree}>
        {collection.rootNode.children?.map((node, index) => (
          <TreeNode key={node.id} node={node} indexPath={[index]} onRemove={removeNode} onAdd={addNode} />
        ))}
      </TreeView.Tree>
    </TreeView.Root>
  )
}

const TreeNodeActions = (props: TreeNodeProps) => {
  const { onRemove, onAdd, node } = props
  const tree = useTreeViewContext()
  const isBranch = tree.collection.isBranchNode(node)
  return (
    <div className={styles.ActionGroup}>
      <button
        className={styles.Action}
        onClick={(e) => {
          e.stopPropagation()
          onRemove?.(props)
        }}
      >
        <TrashIcon />
      </button>
      {isBranch && (
        <button
          className={styles.Action}
          onClick={(e) => {
            e.stopPropagation()
            onAdd?.(props)
            tree.expand([node.id])
          }}
        >
          <PlusIcon />
        </button>
      )}
    </div>
  )
}

interface TreeNodeProps extends TreeView.NodeProviderProps<Node> {
  onRemove?: (props: TreeView.NodeProviderProps<Node>) => void
  onAdd?: (props: TreeView.NodeProviderProps<Node>) => void
}

const TreeNode = (props: TreeNodeProps) => {
  const { node, indexPath } = props
  const tree = useTreeViewContext()
  const nodeState = tree.getNodeState(props)
  return (
    <TreeView.NodeProvider key={node.id} node={node} indexPath={indexPath}>
      {nodeState.isBranch ? (
        <TreeView.NodeGroup className={styles.NodeGroup}>
          <TreeView.Node className={styles.Node}>
            <TreeView.Cell className={styles.Cell}>
              <TreeView.NodeExpandTrigger className={styles.NodeExpandTrigger}>
                <TreeView.NodeIndicator type="expanded" className={styles.NodeIndicator}>
                  <ChevronRightIcon />
                </TreeView.NodeIndicator>
              </TreeView.NodeExpandTrigger>
              <TreeView.NodeText className={styles.NodeText}>{node.name}</TreeView.NodeText>
              <TreeNodeActions {...props} />
            </TreeView.Cell>
          </TreeView.Node>
          <TreeView.NodeGroupContent className={styles.NodeGroupContent}>
            <TreeView.IndentGuide className={styles.IndentGuide} />
            {node.children?.map((child, index) => (
              <TreeNode
                key={child.id}
                node={child}
                indexPath={[...indexPath, index]}
                onRemove={props.onRemove}
                onAdd={props.onAdd}
              />
            ))}
          </TreeView.NodeGroupContent>
        </TreeView.NodeGroup>
      ) : (
        <TreeView.Node className={styles.Node}>
          <TreeView.Cell className={styles.Cell}>
            <TreeView.NodeText className={styles.NodeText}>{node.name}</TreeView.NodeText>
            <TreeNodeActions {...props} />
          </TreeView.Cell>
        </TreeView.Node>
      )}
    </TreeView.NodeProvider>
  )
}

interface Node {
  id: string
  name: string
  children?: Node[]
}

const initialCollection = createTreeCollection<Node>({
  nodeToValue: (node) => node.id,
  nodeToString: (node) => node.name,
  rootNode: {
    id: 'ROOT',
    name: '',
    children: [
      {
        id: 'node_modules',
        name: 'node_modules',
        children: [
          { id: 'node_modules/zag-js', name: 'zag-js' },
          { id: 'node_modules/pandacss', name: 'panda' },
          {
            id: 'node_modules/@types',
            name: '@types',
            children: [
              { id: 'node_modules/@types/react', name: 'react' },
              { id: 'node_modules/@types/react-dom', name: 'react-dom' },
            ],
          },
        ],
      },
      {
        id: 'src',
        name: 'src',
        children: [
          { id: 'src/app.tsx', name: 'app.tsx' },
          { id: 'src/index.ts', name: 'index.ts' },
        ],
      },
      { id: 'panda.config', name: 'panda.config.ts' },
      { id: 'package.json', name: 'package.json' },
      { id: 'renovate.json', name: 'renovate.json' },
      { id: 'readme.md', name: 'README.md' },
    ],
  },
})
```

### Rename Node

Use `canRename` and `onRenameComplete` for inline renaming. Press <kbd>F2</kbd> to rename the focused node.

```tsx
import { TreeView, createTreeCollection } from '@ark-ui/react/tree-view'
import { ChevronRightIcon, FileIcon, FolderIcon, FolderOpenIcon } from 'lucide-react'
import { useState } from 'react'

import styles from 'styles/tree-view.module.css'

export const RenameNode = () => {
  const [collection, setCollection] = useState(initialCollection)
  return (
    <TreeView.Root
      className={styles.Root}
      collection={collection}
      canRename={() => true}
      onRenameComplete={(details) => {
        setCollection((prev) => {
          const node = prev.at(details.indexPath)
          if (!node) return prev
          return prev.replace(details.indexPath, { ...node, name: details.label })
        })
      }}
    >
      <TreeView.Label className={styles.Label}>Tree (Press F2 to rename)</TreeView.Label>
      <TreeView.Tree className={styles.Tree}>
        {collection.rootNode.children?.map((node, index) => (
          <TreeNode key={node.id} node={node} indexPath={[index]} />
        ))}
      </TreeView.Tree>
    </TreeView.Root>
  )
}

const TreeNode = (props: TreeView.NodeProviderProps<Node>) => {
  const { node, indexPath } = props
  return (
    <TreeView.NodeProvider key={node.id} node={node} indexPath={indexPath}>
      <TreeView.NodeContext>
        {(nodeState) =>
          nodeState.isBranch ? (
            <TreeView.NodeGroup className={styles.NodeGroup}>
              <TreeView.Node className={styles.Node}>
                <TreeView.Cell className={styles.Cell}>
                  <TreeView.NodeExpandTrigger className={styles.NodeExpandTrigger}>
                    <TreeView.NodeIndicator type="expanded" className={styles.NodeIndicator}>
                      <ChevronRightIcon />
                    </TreeView.NodeIndicator>
                  </TreeView.NodeExpandTrigger>
                  {nodeState.renaming ? (
                    <TreeView.NodeRenameInput className={styles.NodeRenameInput} />
                  ) : (
                    <TreeView.NodeText className={styles.NodeText}>
                      {nodeState.expanded ? <FolderOpenIcon /> : <FolderIcon />}
                      {node.name}
                    </TreeView.NodeText>
                  )}
                </TreeView.Cell>
              </TreeView.Node>
              <TreeView.NodeGroupContent className={styles.NodeGroupContent}>
                <TreeView.IndentGuide className={styles.IndentGuide} />
                {node.children?.map((child, index) => (
                  <TreeNode key={child.id} node={child} indexPath={[...indexPath, index]} />
                ))}
              </TreeView.NodeGroupContent>
            </TreeView.NodeGroup>
          ) : (
            <TreeView.Node className={styles.Node}>
              <TreeView.Cell className={styles.Cell}>
                <FileIcon />
                {nodeState.renaming ? (
                  <TreeView.NodeRenameInput className={styles.NodeRenameInput} />
                ) : (
                  <TreeView.NodeText className={styles.NodeText}>{node.name}</TreeView.NodeText>
                )}
              </TreeView.Cell>
            </TreeView.Node>
          )
        }
      </TreeView.NodeContext>
    </TreeView.NodeProvider>
  )
}

interface Node {
  id: string
  name: string
  children?: Node[]
}

const initialCollection = createTreeCollection<Node>({
  nodeToValue: (node) => node.id,
  nodeToString: (node) => node.name,
  rootNode: {
    id: 'ROOT',
    name: '',
    children: [
      {
        id: 'node_modules',
        name: 'node_modules',
        children: [
          { id: 'node_modules/zag-js', name: 'zag-js' },
          { id: 'node_modules/pandacss', name: 'panda' },
          {
            id: 'node_modules/@types',
            name: '@types',
            children: [
              { id: 'node_modules/@types/react', name: 'react' },
              { id: 'node_modules/@types/react-dom', name: 'react-dom' },
            ],
          },
        ],
      },
      {
        id: 'src',
        name: 'src',
        children: [
          { id: 'src/app.tsx', name: 'app.tsx' },
          { id: 'src/index.ts', name: 'index.ts' },
        ],
      },
      { id: 'panda.config', name: 'panda.config.ts' },
      { id: 'package.json', name: 'package.json' },
      { id: 'renovate.json', name: 'renovate.json' },
      { id: 'readme.md', name: 'README.md' },
    ],
  },
})
```

## Guides

### Type Safety

Use the `TreeView.RootComponent` type to build wrappers that keep tree nodes fully typed.

```tsx
import { TreeView as ArkTreeView } from '@ark-ui/react/tree-view'

const TreeView: ArkTreeView.RootComponent = (props) => {
  return <ArkTreeView.Root {...props}>{/* ... */}</ArkTreeView.Root>
}
```

`onSelectionChange` and other callbacks then infer the node type:

```tsx
const App = () => {
  const collection = createTreeCollection({
    initialItems: [
      { id: '1', label: 'React', children: [] },
      { id: '2', label: 'Vue', children: [] },
    ],
  })
  return (
    <TreeView
      collection={collection}
      onSelectionChange={(e) => {
        // e.items is typed as Array<{ id: string, label: string, children: [] }>
        console.log(e.items)
      }}
    >
      {/* ... */}
    </TreeView>
  )
}
```

## API Reference

### Props

### Root

#### Props

**`collection`**
Type: `TreeCollection<T>`
Required: true
Default Value: `undefined`
Description: The collection of tree nodes

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`canRename`**
Type: `(node: T, indexPath: IndexPath) => boolean`
Required: false
Default Value: `undefined`
Description: Function to determine if a node can be renamed

**`checkedValue`**
Type: `string[]`
Required: false
Default Value: `undefined`
Description: The controlled checked node value

**`defaultCheckedValue`**
Type: `string[]`
Required: false
Default Value: `undefined`
Description: The initial checked node value when rendered.
Use when you don't need to control the checked node value.

**`defaultExpandedValue`**
Type: `string[]`
Required: false
Default Value: `undefined`
Description: The initial expanded node ids when rendered.
Use when you don't need to control the expanded node value.

**`defaultFocusedValue`**
Type: `string`
Required: false
Default Value: `undefined`
Description: The initial focused node value when rendered.
Use when you don't need to control the focused node value.

**`defaultSelectedValue`**
Type: `string[]`
Required: false
Default Value: `undefined`
Description: The initial selected node value when rendered.
Use when you don't need to control the selected node value.

**`expandedValue`**
Type: `string[]`
Required: false
Default Value: `undefined`
Description: The controlled expanded node ids

**`expandOnClick`**
Type: `boolean`
Required: false
Default Value: `true`
Description: Whether clicking on a branch should open it or not

**`focusedValue`**
Type: `string`
Required: false
Default Value: `undefined`
Description: The value of the focused node

**`hideMode`**
Type: `HideMode`
Required: false
Default Value: `'display-none'`
Description: How to hide content when mounted but not present.
- `'display-none'`: HTML `hidden` attribute. Effects stay alive.
- `'activity'`: React 19 `<Activity mode="hidden">`. Effects pause. Requires React 19+.

**`ids`**
Type: `ElementIds`
Required: false
Default Value: `undefined`
Description: The ids of the tree elements. Useful for composition.

**`lazyMount`**
Type: `boolean`
Required: false
Default Value: `false`
Description: Whether to enable lazy mounting

**`loadChildren`**
Type: `(details: LoadChildrenDetails<T>) => Promise<T[]>`
Required: false
Default Value: `undefined`
Description: Function to load children for a node asynchronously.
When provided, branches will wait for this promise to resolve before expanding.

**`onBeforeRename`**
Type: `(details: RenameCompleteDetails) => boolean`
Required: false
Default Value: `undefined`
Description: Called before a rename is completed. Return false to prevent the rename.

**`onCheckedChange`**
Type: `(details: CheckedChangeDetails) => void`
Required: false
Default Value: `undefined`
Description: Called when the checked value changes

**`onExpandedChange`**
Type: `(details: ExpandedChangeDetails<T>) => void`
Required: false
Default Value: `undefined`
Description: Called when the tree is opened or closed

**`onFocusChange`**
Type: `(details: FocusChangeDetails<T>) => void`
Required: false
Default Value: `undefined`
Description: Called when the focused node changes

**`onLoadChildrenComplete`**
Type: `(details: LoadChildrenCompleteDetails<T>) => void`
Required: false
Default Value: `undefined`
Description: Called when a node finishes loading children

**`onLoadChildrenError`**
Type: `(details: LoadChildrenErrorDetails<T>) => void`
Required: false
Default Value: `undefined`
Description: Called when loading children fails for one or more nodes

**`onRenameComplete`**
Type: `(details: RenameCompleteDetails) => void`
Required: false
Default Value: `undefined`
Description: Called when a node label rename is completed

**`onRenameStart`**
Type: `(details: RenameStartDetails<T>) => void`
Required: false
Default Value: `undefined`
Description: Called when a node starts being renamed

**`onSelectionChange`**
Type: `(details: SelectionChangeDetails<T>) => void`
Required: false
Default Value: `undefined`
Description: Called when the selection changes

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

**`scrollToIndexFn`**
Type: `(details: ScrollToIndexDetails<T>) => void`
Required: false
Default Value: `undefined`
Description: Function to scroll to a specific index.
Useful for virtualized tree views.

**`selectedValue`**
Type: `string[]`
Required: false
Default Value: `undefined`
Description: The controlled selected node value

**`selectionMode`**
Type: `'multiple' | 'single'`
Required: false
Default Value: `"single"`
Description: Whether the tree supports multiple selection
- "single": only one node can be selected
- "multiple": multiple nodes can be selected

**`translations`**
Type: `IntlTranslations`
Required: false
Default Value: `undefined`
Description: Specifies the localized strings that identifies the accessibility elements and their states

**`typeahead`**
Type: `boolean`
Required: false
Default Value: `true`
Description: Whether the tree supports typeahead search

**`unmountOnExit`**
Type: `boolean`
Required: false
Default Value: `false`
Description: Whether to unmount on exit.

### Cell

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

### IndentGuide

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

#### Data Attributes

**`data-tree-view-indent-guide`**: <uid>
**`data-depth`**: The depth of the item

### Label

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

### NodeCheckbox

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

#### Data Attributes

**`data-tree-view-node-checkbox`**: <uid>
**`data-state`**: "checked" | "unchecked" | "indeterminate"
**`data-disabled`**: Present when disabled

### NodeExpandTrigger

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

#### Data Attributes

**`data-tree-view-node-expand-trigger`**: <uid>
**`data-disabled`**: Present when disabled
**`data-state`**: "open" | "closed"
**`data-value`**: The value of the item
**`data-loading`**: Present when loading

### NodeGroupContent

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

#### Data Attributes

**`data-tree-view-node-group-content`**: <uid>
**`data-state`**: "open" | "closed"
**`data-depth`**: The depth of the item
**`data-path`**: The path of the item
**`data-value`**: The value of the item

### NodeGroup

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

#### Data Attributes

**`data-tree-view-node-group`**: <uid>
**`data-depth`**: The depth of the item
**`data-value`**: The value of the item
**`data-path`**: The path of the item
**`data-state`**: "open" | "closed"
**`data-disabled`**: Present when disabled
**`data-loading`**: Present when loading

### NodeIndicator

#### Props

**`type`**
Type: `NodeIndicatorType`
Required: true
Default Value: `undefined`
Description: The type of indicator
- "expanded": always visible, reflects open/closed state
- "selected": shown when the node is selected
- "checked": shown when the node is checked
- "indeterminate": shown when the node is indeterminate (partially checked)

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

#### Data Attributes

**`data-tree-view-node-indicator`**: <uid>
**`data-type`**: The type of the item
**`data-state`**: "expanded" | "open" | "closed"
**`data-disabled`**: Present when disabled
**`data-selected`**: Present when selected
**`data-focus`**: Present when focused
**`data-loading`**: Present when loading

### Node

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<TreeViewNodeState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

#### Data Attributes

**`data-tree-view-node`**: <uid>
**`data-path`**: The path of the item
**`data-value`**: The value of the item
**`data-focus`**: Present when focused
**`data-selected`**: Present when selected
**`data-state`**: "open" | "closed"
**`data-disabled`**: Present when disabled
**`data-renaming`**: 
**`data-checked`**: Present when checked
**`data-indeterminate`**: 
**`data-depth`**: The depth of the item
**`data-loading`**: Present when loading
**`data-branch`**: 

### NodeProvider

#### Props

**`indexPath`**
Type: `number[]`
Required: true
Default Value: `undefined`
Description: The index path of the tree node

**`node`**
Type: `NonNullable<T>`
Required: false
Default Value: `undefined`
Description: The tree node

### NodeRenameInput

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

### NodeText

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

#### Data Attributes

**`data-tree-view-node-text`**: <uid>
**`data-disabled`**: Present when disabled
**`data-selected`**: Present when selected
**`data-focus`**: Present when focused
**`data-state`**: "open" | "closed"
**`data-loading`**: Present when loading

### RootProvider

#### Props

**`value`**
Type: `UseTreeViewReturn<T>`
Required: true
Default Value: `undefined`
Description: undefined

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`hideMode`**
Type: `HideMode`
Required: false
Default Value: `'display-none'`
Description: How to hide content when mounted but not present.
- `'display-none'`: HTML `hidden` attribute. Effects stay alive.
- `'activity'`: React 19 `<Activity mode="hidden">`. Effects pause. Requires React 19+.

**`lazyMount`**
Type: `boolean`
Required: false
Default Value: `false`
Description: Whether to enable lazy mounting

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

**`unmountOnExit`**
Type: `boolean`
Required: false
Default Value: `false`
Description: Whether to unmount on exit.

### Tree

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

#### Data Attributes

**`data-tree-view-tree`**: <uid>
**`data-branch`**: 

### Context

**API:**

| Property | Type | Description |
|----------|------|-------------|
| `collection` | `TreeCollection<V>` | The tree collection data |
| `expandedValue` | `string[]` | The value of the expanded nodes. |
| `setExpandedValue` | `(value: string[]) => void` | Sets the expanded value |
| `selectedValue` | `string[]` | The value of the selected nodes. |
| `setSelectedValue` | `(value: string[]) => void` | Sets the selected value |
| `checkedValue` | `string[]` | The value of the checked nodes |
| `toggleChecked` | `(value: string, isBranch: boolean) => void` | Toggles the checked value of a node |
| `setChecked` | `(value: string[]) => void` | Sets the checked value of a node |
| `clearChecked` | `VoidFunction` | Clears the checked value of a node |
| `getCheckedMap` | `() => CheckedValueMap` | Returns the checked details of branch and leaf nodes |
| `getVisibleNodes` | `() => VisibleNode<V>[]` | Returns the visible nodes as a flat array of nodes and their index path.
Useful for rendering virtualized tree views. |
| `expand` | `(value?: string[]) => void` | Function to expand nodes.
If no value is provided, all nodes will be expanded |
| `collapse` | `(value?: string[]) => void` | Function to collapse nodes
If no value is provided, all nodes will be collapsed |
| `select` | `(value?: string[]) => void` | Function to select nodes
If no value is provided, all nodes will be selected |
| `deselect` | `(value?: string[]) => void` | Function to deselect nodes
If no value is provided, all nodes will be deselected |
| `focus` | `(value: string) => void` | Function to focus a node by value |
| `selectParent` | `(value: string) => void` | Function to select the parent node of the focused node |
| `expandParent` | `(value: string) => void` | Function to expand the parent node of the focused node |
| `startRenaming` | `(value: string) => void` | Function to start renaming a node by value |
| `submitRenaming` | `(value: string, label: string) => void` | Function to submit the rename and update the node label |
| `cancelRenaming` | `() => void` | Function to cancel renaming without changes |
| `getNodeState` | `(props: NodeProps) => NodeState` | Returns the state of a node including whether it's selected, expanded,
focused, disabled, checked, loading, renaming, and its depth/path info. |


## Accessibility

Complies with the [Tree View WAI-ARIA design pattern](https://www.w3.org/WAI/ARIA/apg/patterns/treeview/).

### Keyboard Support

**`Tab`**
Description: Moves focus to the tree view, placing the first tree view item in focus.

**`Enter + Space`**
Description: Selects the item or branch node

**`ArrowDown`**
Description: Moves focus to the next node

**`ArrowUp`**
Description: Moves focus to the previous node

**`ArrowRight`**
Description: When focus is on a closed branch node, opens the branch.<br> When focus is on an open branch node, moves focus to the first item node.

**`ArrowLeft`**
Description: When focus is on an open branch node, closes the node.<br> When focus is on an item or branch node, moves focus to its parent branch node.

**`Home`**
Description: Moves focus to first node without opening or closing a node.

**`End`**
Description: Moves focus to the last node that can be focused without expanding any nodes that are closed.

**`a-z + A-Z`**
Description: Focus moves to the next node with a name that starts with the typed character. The search logic ignores nodes that are descendants of closed branch.

**`*`**
Description: Expands all sibling nodes that are at the same depth as the focused node.

**`Shift + ArrowDown`**
Description: Moves focus to and toggles the selection state of the next node.

**`Shift + ArrowUp`**
Description: Moves focus to and toggles the selection state of the previous node.

**`Ctrl + A`**
Description: Selects all nodes in the tree. If all nodes are selected, unselects all nodes.
