Tree View
A component that is used to show a tree hierarchy.
A component that is used to show a tree hierarchy.
Please note that this component will only be available in the next minor release.
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-partattribute 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'
const Basic = () => {
return (
<TreeView.Root>
<TreeView.Label>My Documents</TreeView.Label>
<TreeView.Tree>
<TreeView.Branch id="node_modules" depth={1}>
<TreeView.BranchControl id="node_modules" depth={1}>
<TreeView.BranchText id="node_modules" depth={1}>
📂 node_modules
</TreeView.BranchText>
</TreeView.BranchControl>
<TreeView.BranchContent id="node_modules" depth={1}>
<TreeView.Item id="node_modules/zag-js" depth={2}>
📄 zag-js
</TreeView.Item>
<TreeView.Item id="node_modules/pandacss" depth={2}>
📄 panda
</TreeView.Item>
<TreeView.Branch id="node_modules/@types" depth={2}>
<TreeView.BranchControl id="node_modules/@types" depth={2}>
<TreeView.BranchText id="node_modules/@types" depth={2}>
📂 @types
</TreeView.BranchText>
</TreeView.BranchControl>
<TreeView.BranchContent id="node_modules/@types" depth={2}>
<TreeView.Item id="node_modules/@types/react" depth={3}>
📄 react
</TreeView.Item>
<TreeView.Item id="node_modules/@types/react-dom" depth={3}>
📄 react-dom
</TreeView.Item>
</TreeView.BranchContent>
</TreeView.Branch>
</TreeView.BranchContent>
</TreeView.Branch>
<TreeView.Branch id="src" depth={1}>
<TreeView.BranchControl id="src" depth={1}>
<TreeView.BranchText id="src" depth={1}>
📂 src
</TreeView.BranchText>
</TreeView.BranchControl>
<TreeView.BranchContent id="src" depth={1}>
<TreeView.Item id="src/app.tsx" depth={2}>
📄 app.tsx
</TreeView.Item>
<TreeView.Item id="src/index.ts" depth={2}>
📄 index.ts
</TreeView.Item>
</TreeView.BranchContent>
</TreeView.Branch>
<TreeView.Item id="panda.config" depth={1}>
📄 panda.config.ts
</TreeView.Item>
<TreeView.Item id="package.json" depth={1}>
📄 package.json
</TreeView.Item>
<TreeView.Item id="renovate.json" depth={1}>
📄 renovate.json
</TreeView.Item>
<TreeView.Item id="readme.md" depth={1}>
📄 README.md
</TreeView.Item>
</TreeView.Tree>
</TreeView.Root>
)
}
import { TreeView } from '@ark-ui/solid'
const Basic = () => {
return (
<TreeView.Root>
<TreeView.Label>My Documents</TreeView.Label>
<TreeView.Tree>
<TreeView.Branch id="node_modules" depth={1}>
<TreeView.BranchControl id="node_modules" depth={1}>
<TreeView.BranchText id="node_modules" depth={1}>
📂 node_modules
</TreeView.BranchText>
</TreeView.BranchControl>
<TreeView.BranchContent id="node_modules" depth={1}>
<TreeView.Item id="node_modules/zag-js" depth={2}>
📄 zag-js
</TreeView.Item>
<TreeView.Item id="node_modules/pandacss" depth={2}>
📄 panda
</TreeView.Item>
<TreeView.Branch id="node_modules/@types" depth={2}>
<TreeView.BranchControl id="node_modules/@types" depth={2}>
<TreeView.BranchText id="node_modules/@types" depth={2}>
📂 @types
</TreeView.BranchText>
</TreeView.BranchControl>
<TreeView.BranchContent id="node_modules/@types" depth={2}>
<TreeView.Item id="node_modules/@types/react" depth={3}>
📄 react
</TreeView.Item>
<TreeView.Item id="node_modules/@types/react-dom" depth={3}>
📄 react-dom
</TreeView.Item>
</TreeView.BranchContent>
</TreeView.Branch>
</TreeView.BranchContent>
</TreeView.Branch>
<TreeView.Branch id="src" depth={1}>
<TreeView.BranchControl id="src" depth={1}>
<TreeView.BranchText id="src" depth={1}>
📂 src
</TreeView.BranchText>
</TreeView.BranchControl>
<TreeView.BranchContent id="src" depth={1}>
<TreeView.Item id="src/app.tsx" depth={2}>
📄 app.tsx
</TreeView.Item>
<TreeView.Item id="src/index.ts" depth={2}>
📄 index.ts
</TreeView.Item>
</TreeView.BranchContent>
</TreeView.Branch>
<TreeView.Item id="panda.config" depth={1}>
📄 panda.config.ts
</TreeView.Item>
<TreeView.Item id="package.json" depth={1}>
📄 package.json
</TreeView.Item>
<TreeView.Item id="renovate.json" depth={1}>
📄 renovate.json
</TreeView.Item>
<TreeView.Item id="readme.md" depth={1}>
📄 README.md
</TreeView.Item>
</TreeView.Tree>
</TreeView.Root>
)
}
<script setup lang="ts">
import { TreeView } from '@ark-ui/vue'
</script>
<template>
<TreeView.Root>
<TreeView.Label>My Documents</TreeView.Label>
<TreeView.Tree>
<TreeView.Branch id="node_modules" :depth="1">
<TreeView.BranchControl id="node_modules" :depth="1">
<TreeView.BranchText id="node_modules" :depth="1"> 📂 node_modules </TreeView.BranchText>
</TreeView.BranchControl>
<TreeView.BranchContent id="node_modules" :depth="1">
<TreeView.Item id="node_modules/zag-js" :depth="2"> 📄 zag-js </TreeView.Item>
<TreeView.Item id="node_modules/pandacss" :depth="2"> 📄 panda </TreeView.Item>
<TreeView.Branch id="node_modules/@types" :depth="2">
<TreeView.BranchControl id="node_modules/@types" :depth="2">
<TreeView.BranchText id="node_modules/@types" :depth="2">
📂 @types
</TreeView.BranchText>
</TreeView.BranchControl>
<TreeView.BranchContent id="node_modules/@types" :depth="2">
<TreeView.Item id="node_modules/@types/react" :depth="3"> 📄 react </TreeView.Item>
<TreeView.Item id="node_modules/@types/react-dom" :depth="3">
📄 react-dom
</TreeView.Item>
</TreeView.BranchContent>
</TreeView.Branch>
</TreeView.BranchContent>
</TreeView.Branch>
<TreeView.Branch id="src" :depth="1">
<TreeView.BranchControl id="src" :depth="1">
<TreeView.BranchText id="src" :depth="1"> 📂 src </TreeView.BranchText>
</TreeView.BranchControl>
<TreeView.BranchContent id="src" :depth="1">
<TreeView.Item id="src/app.tsx" :depth="2"> 📄 app.tsx </TreeView.Item>
<TreeView.Item id="src/index.ts" :depth="2"> 📄 index.ts </TreeView.Item>
</TreeView.BranchContent>
</TreeView.Branch>
<TreeView.Item id="panda.config" :depth="1"> 📄 panda.config.ts </TreeView.Item>
<TreeView.Item id="package.json" :depth="1"> 📄 package.json </TreeView.Item>
<TreeView.Item id="renovate.json" :depth="1"> 📄 renovate.json </TreeView.Item>
<TreeView.Item id="readme.md" :depth="1"> 📄 README.md </TreeView.Item>
</TreeView.Tree>
</TreeView.Root>
</template>
depth | number | |
id | string | |
asChildRender as a different element type. | boolean | |
disabled | boolean |
asChildRender as a different element type. | boolean | |
defaultFocusedIdThe initial focused index of the tree view. | string | |
dirThe document's text/writing direction. | 'ltr' | 'rtl' | "ltr" |
expandedIdsThe id of the expanded nodes | Set<string> | |
focusedIdThe id of the focused node | string | |
getRootNodeA root node to correctly resolve document in custom environments. E.x.: Iframes, Electron. | () => Node | ShadowRoot | Document | |
idThe unique identifier of the machine. | string | |
onExpandedChangeCalled when the tree is opened or closed | (details: ExpandedChangeDetails) => void | |
onFocusChangeCalled when the focused node changes | (details: FocusChangeDetails) => void | |
onSelectionChangeCalled when the selection changes | (details: SelectionChangeDetails) => void | |
openOnClickWhether clicking on a branch should open it or not | boolean | true |
selectedIdsThe id of the selected nodes | Set<string> | |
selectionModeWhether the tree supports multiple selection - "single": only one node can be selected - "multiple": multiple nodes can be selected | 'multiple' | 'single' | "single" |
asChildRender as a different element type. | boolean |
asChildRender as a different element type. | boolean |
depth | number | |
id | string | |
asChildRender as a different element type. | boolean | |
disabled | boolean |
depth | number | |
id | string | |
asChildRender as a different element type. | boolean | |
disabled | boolean |
depth | number | |
id | string | |
asChildRender as a different element type. | boolean | |
disabled | boolean |
depth | number | |
id | string | |
asChildRender as a different element type. | boolean | |
disabled | boolean |
depth | number | |
id | string | |
asChildRender as a different element type. | boolean | |
disabled | boolean |
depth | number | |
id | string | |
asChildRender as a different element type. | boolean | |
disabled | boolean |
depth | number | |
id | string | |
asChildRender as a different element type. | boolean | |
disabled | boolean |