Ark Logo

Tree View

A component that is used to show a tree hierarchy.

Anatomy

To set up the tree view component correctly, you'll need to understand its anatomy and how we name its parts.

Each part includes a data-part attribute to help identify them in the DOM.

Examples

Learn how to use the TreeView component in your project. Let's take a look at the most basic example:

import { TreeView } from '@ark-ui/react'

export const Basic = () => {
  return (
    <TreeView.Root>
      <TreeView.Label>Tree</TreeView.Label>
      <TreeView.Tree>
        <TreeView.Item value="1.0">
          <TreeView.ItemText>1.0</TreeView.ItemText>
        </TreeView.Item>
        <TreeView.Branch value="2.0">
          <TreeView.BranchControl>
            <TreeView.BranchIndicator>↕️</TreeView.BranchIndicator>
            <TreeView.BranchText>2.0</TreeView.BranchText>
          </TreeView.BranchControl>
          <TreeView.BranchContent>
            <TreeView.Item value="2.1">
              <TreeView.ItemText>2.2</TreeView.ItemText>
            </TreeView.Item>
            <TreeView.Item value="2.2">
              <TreeView.ItemText>2.2</TreeView.ItemText>
            </TreeView.Item>
          </TreeView.BranchContent>
        </TreeView.Branch>
      </TreeView.Tree>
    </TreeView.Root>
  )
}

API Reference

Root

PropDefaultType
asChild
boolean

Render as a different element type.

defaultExpandedValue
string[]

The initial expanded items of the tree view. Use this when you do not need to control the state of the tree view.

defaultSelectedValue
string[]

The initial selected items of the tree view. Use this when you do not need to control the state of the tree view.

expandedValue
string[]

The id of the expanded nodes

focusedValue
string

The id of the focused node

id
string

The unique identifier of the machine.

ids
Partial<{ root: string; tree: string; label: string }>

The ids of the tree elements. Useful for composition.

onExpandedChange
(details: ExpandedChangeDetails) => void

Called when the tree is opened or closed

onFocusChange
(details: FocusChangeDetails) => void

Called when the focused node changes

onSelectionChange
(details: SelectionChangeDetails) => void

Called when the selection changes

openOnClicktrue
boolean

Whether clicking on a branch should open it or not

selectedValue
string[]

The id of the selected nodes

selectionMode'single'
'multiple' | 'single'

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

typeahead
boolean

Whether the tree supports typeahead search

BranchContent

PropDefaultType
asChild
boolean

Render as a different element type.

BranchControl

PropDefaultType
asChild
boolean

Render as a different element type.

BranchIndicator

PropDefaultType
asChild
boolean

Render as a different element type.

Branch

PropDefaultType
value
string

The id of the item or branch

asChild
boolean

Render as a different element type.

disabled
boolean

Whether the item or branch is disabled

BranchText

PropDefaultType
asChild
boolean

Render as a different element type.

BranchTrigger

PropDefaultType
asChild
boolean

Render as a different element type.

ItemIndicator

PropDefaultType
asChild
boolean

Render as a different element type.

Item

PropDefaultType
value
string

The id of the item or branch

asChild
boolean

Render as a different element type.

disabled
boolean

Whether the item or branch is disabled

ItemText

PropDefaultType
asChild
boolean

Render as a different element type.

Label

PropDefaultType
asChild
boolean

Render as a different element type.

Tree

PropDefaultType
asChild
boolean

Render as a different element type.