Tree View
A component that is used to show a tree hierarchy.
A component that is used to show a tree hierarchy.
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.
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>
)
}
import { TreeView } from '@ark-ui/solid'
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.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>
)
}
<script setup lang="ts">
import { TreeView } from '@ark-ui/vue'
</script>
<template>
<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.BranchTrigger>↕️</TreeView.BranchTrigger>
<TreeView.BranchText>2.0</TreeView.BranchText>
<TreeView.BranchIndicator>↕️</TreeView.BranchIndicator>
</TreeView.BranchControl>
<TreeView.BranchContent>
<TreeView.Item value="2.1">
<TreeView.ItemText>2.1</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>
</template>
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean | |
defaultExpandedValue The initial expanded items of the tree view.
Use this when you do not need to control the state of the tree view. | string[] | |
defaultSelectedValue The initial selected items of the tree view.
Use this when you do not need to control the state of the tree view. | string[] | |
expandedValue The id of the expanded nodes | string[] | |
focusedValue The id of the focused node | string | |
id The unique identifier of the machine. | string | |
ids The ids of the tree elements. Useful for composition. | Partial<{ root: string; tree: string; label: string }> | |
onExpandedChange Called when the tree is opened or closed | (details: ExpandedChangeDetails) => void | |
onFocusChange Called when the focused node changes | (details: FocusChangeDetails) => void | |
onSelectionChange Called when the selection changes | (details: SelectionChangeDetails) => void | |
openOnClick Whether clicking on a branch should open it or not | boolean | true |
selectedValue The id of the selected nodes | string[] | |
selectionMode Whether the tree supports multiple selection
- "single": only one node can be selected
- "multiple": multiple nodes can be selected | 'multiple' | 'single' | "single" |
typeahead Whether the tree supports typeahead search | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
value The id of the item or branch | string | |
asChild Render as a different element type. | boolean | |
disabled Whether the item or branch is disabled | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
value The id of the item or branch | string | |
asChild Render as a different element type. | boolean | |
disabled Whether the item or branch is disabled | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Previous
TooltipNext
Environment