Skip to Content
Documentation
Getting startedComponentsChartsTheming
Get Pro
Overview
Concepts

Tree View

Used to display hierarchical data structures in an expandable tree format

Recipe

Tree

panda.config.ts
package.json
renovate.json
README.md

Anatomy

import { TreeView, createTreeCollection } from '@chakra-ui/react'
<TreeView.Root collection={collection}>
  <TreeView.Label />
  <TreeView.Tree>
    <TreeView.Branch>
      <TreeView.BranchControl>
        <TreeView.BranchIndicator />
        <TreeView.BranchText />
      </TreeView.BranchControl>
      <TreeView.BranchContent>
        <TreeView.BranchIndentGuide />
        <TreeView.Item />
      </TreeView.BranchContent>
    </TreeView.Branch>
    <TreeView.Item />
  </TreeView.Tree>
</TreeView.Root>

Use the createTreeCollection function to register the tree data before rendering the tree view.

Shortcuts

TreeView.Node

This component is a helper that manages the recursive rendering of the branch and leaf nodes for you.

<TreeView.Node
  indentGuide={<TreeView.BranchIndentGuide />}
  render={({ node, nodeState }) =>
    nodeState.isBranch ? (
      <TreeView.BranchControl>
        <TreeView.BranchText>{node.name}</TreeView.BranchText>
      </TreeView.BranchControl>
    ) : (
      <TreeView.Item>
        <TreeView.ItemText>{node.name}</TreeView.ItemText>
      </TreeView.Item>
    )
  }
/>

is equivalent to:

const TreeNode = (props) => {
  const { node, indexPath } = props
  return (
    <TreeView.NodeProvider key={node.id} node={node} indexPath={indexPath}>
      {node.children ? (
        <TreeView.Branch>
          <TreeView.BranchControl>
            <TreeView.BranchText>{node.name}</TreeView.BranchText>
          </TreeView.BranchControl>
          <TreeView.BranchContent>
            <TreeView.BranchIndentGuide />
            {node.children.map((child, index) => (
              <TreeNode
                key={child.id}
                node={child}
                indexPath={[...indexPath, index]}
              />
            ))}
          </TreeView.BranchContent>
        </TreeView.Branch>
      ) : (
        <TreeView.Item>
          <TreeView.ItemText>{node.name}</TreeView.ItemText>
        </TreeView.Item>
      )}
    </TreeView.NodeProvider>
  )
}

Examples

Sizes

Use the size prop to change the size of the tree view.

Tree (size=xs)

panda.config.ts
package.json
renovate.json
README.md

Tree (size=sm)

panda.config.ts
package.json
renovate.json
README.md

Tree (size=md)

panda.config.ts
package.json
renovate.json
README.md

Variants

Use the variant prop to change the variant of the tree view.

Tree (variant=subtle)

panda.config.ts
package.json
renovate.json
README.md

Tree (variant=solid)

panda.config.ts
package.json
renovate.json
README.md

Colors

Use the colorPalette prop to change the color palette of the tree view.

Tree (colorPalette=gray)

panda.config.ts
package.json
renovate.json
README.md

Tree (colorPalette=zinc)

panda.config.ts
package.json
renovate.json
README.md

Tree (colorPalette=neutral)

panda.config.ts
package.json
renovate.json
README.md

Tree (colorPalette=stone)

panda.config.ts
package.json
renovate.json
README.md

Tree (colorPalette=red)

panda.config.ts
package.json
renovate.json
README.md

Tree (colorPalette=orange)

panda.config.ts
package.json
renovate.json
README.md

Tree (colorPalette=amber)

panda.config.ts
package.json
renovate.json
README.md

Tree (colorPalette=yellow)

panda.config.ts
package.json
renovate.json
README.md

Tree (colorPalette=lime)

panda.config.ts
package.json
renovate.json
README.md

Tree (colorPalette=green)

panda.config.ts
package.json
renovate.json
README.md

Tree (colorPalette=emerald)

panda.config.ts
package.json
renovate.json
README.md

Tree (colorPalette=teal)

panda.config.ts
package.json
renovate.json
README.md

Tree (colorPalette=cyan)

panda.config.ts
package.json
renovate.json
README.md

Tree (colorPalette=sky)

panda.config.ts
package.json
renovate.json
README.md

Tree (colorPalette=blue)

panda.config.ts
package.json
renovate.json
README.md

Tree (colorPalette=indigo)

panda.config.ts
package.json
renovate.json
README.md

Tree (colorPalette=violet)

panda.config.ts
package.json
renovate.json
README.md

Tree (colorPalette=purple)

panda.config.ts
package.json
renovate.json
README.md

Tree (colorPalette=fuchsia)

panda.config.ts
package.json
renovate.json
README.md

Tree (colorPalette=pink)

panda.config.ts
package.json
renovate.json
README.md

Tree (colorPalette=rose)

panda.config.ts
package.json
renovate.json
README.md

Disabled Node

Adding the disabled prop to a node's property will disable the node and prevent interaction.

Tree

panda.config.ts
package.json
renovate.json
README.md

Controlled Expansion

Use the expandedValue and onExpandedChange props to programmatically control node expansion behavior.

Tree

node_modules
zag-js
panda
panda.config.ts
package.json
renovate.json
README.md

Expand Icon

Use the nodeState.expanded property to swap the rendered icon on the branch when it's expanded or collapsed.

Tree

panda.config.ts
package.json
renovate.json
README.md

Checkbox Tree

Add checkboxes to tree nodes for selection functionality. Render the TreeView.NodeCheckbox component and read the node's checked state from the useTreeViewNodeContext hook.

Tree

panda.config.ts
package.json
renovate.json
README.md

Props

Root

PropDefaultType
collection *
TreeCollection<T>

The collection of tree nodes

expandOnClick true
boolean

Whether clicking on a branch should open it or not

hideMode ''display-none''
HideMode

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 false
boolean

Whether to enable lazy mounting

selectionMode '\'single\''
'multiple' | 'single'

Whether the tree supports multiple selection - "single": only one node can be selected - "multiple": multiple nodes can be selected

typeahead true
boolean

Whether the tree supports typeahead search

unmountOnExit false
boolean

Whether to unmount on exit.

colorPalette 'gray'
'base' | 'gray' | 'zinc' | 'neutral' | 'stone' | 'red' | 'orange' | 'amber' | 'yellow' | 'lime' | 'green' | 'emerald' | 'teal' | 'cyan' | 'sky' | 'blue' | 'indigo' | 'violet' | 'purple' | 'fuchsia' | 'pink' | 'rose' | 'sidebar' | 'sidebar.accent' | 'interaction' | 'accent' | 'presence' | 'status' | 'slate'

The color palette of the component

size 'md'
'md' | 'sm' | 'xs'

The size of the component

variant 'subtle'
'subtle' | 'solid'

The variant of the component

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
canRename
(node: T, indexPath: IndexPath) => boolean

Function to determine if a node can be renamed

checkedValue
string[]

The controlled checked node value

defaultCheckedValue
string[]

The initial checked node value when rendered. Use when you don't need to control the checked node value.

defaultExpandedValue
string[]

The initial expanded node ids when rendered. Use when you don't need to control the expanded node value.

defaultFocusedValue
string

The initial focused node value when rendered. Use when you don't need to control the focused node value.

defaultSelectedValue
string[]

The initial selected node value when rendered. Use when you don't need to control the selected node value.

expandedValue
string[]

The controlled expanded node ids

focusedValue
string

The value of the focused node

ids
Partial<{ root: string; tree: string; label: string; node: (value: string) => string }>

The ids of the tree elements. Useful for composition.

loadChildren
(details: LoadChildrenDetails<T>) => Promise<T[]>

Function to load children for a node asynchronously. When provided, branches will wait for this promise to resolve before expanding.

onBeforeRename
(details: RenameCompleteDetails) => boolean

Called before a rename is completed. Return false to prevent the rename.

onCheckedChange
(details: CheckedChangeDetails) => void

Called when the checked value changes

onExpandedChange
(details: ExpandedChangeDetails<T>) => void

Called when the tree is opened or closed

onFocusChange
(details: FocusChangeDetails<T>) => void

Called when the focused node changes

onLoadChildrenComplete
(details: LoadChildrenCompleteDetails<T>) => void

Called when a node finishes loading children

onLoadChildrenError
(details: LoadChildrenErrorDetails<T>) => void

Called when loading children fails for one or more nodes

onRenameComplete
(details: RenameCompleteDetails) => void

Called when a node label rename is completed

onRenameStart
(details: RenameStartDetails<T>) => void

Called when a node starts being renamed

onSelectionChange
(details: SelectionChangeDetails<T>) => void

Called when the selection changes

scrollToIndexFn
(details: ScrollToIndexDetails<T>) => void

Function to scroll to a specific index. Useful for virtualized tree views.

selectedValue
string[]

The controlled selected node value

translations
IntlTranslations

Specifies the localized strings that identifies the accessibility elements and their states

animateContent
'true' | 'false'

The animateContent of the component

Item

PropDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.