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-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'
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 | |
asChild Render as a different element type. | boolean | |
disabled | boolean |
asChild Render as a different element type. | boolean | |
defaultFocusedId The initial focused index of the tree view. | string | |
dir The document's text/writing direction. | 'ltr' | 'rtl' | "ltr" |
expandedIds The id of the expanded nodes | Set<string> | |
focusedId The id of the focused node | string | |
getRootNode A root node to correctly resolve document in custom environments. E.x.: Iframes, Electron. | () => Node | ShadowRoot | Document | |
id The unique identifier of the machine. | 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 |
selectedIds The id of the selected nodes | Set<string> | |
selectionMode Whether the tree supports multiple selection - "single": only one node can be selected - "multiple": multiple nodes can be selected | 'multiple' | 'single' | "single" |
asChild Render as a different element type. | boolean |
asChild Render as a different element type. | boolean |
depth | number | |
id | string | |
asChild Render as a different element type. | boolean | |
disabled | boolean |
depth | number | |
id | string | |
asChild Render as a different element type. | boolean | |
disabled | boolean |
depth | number | |
id | string | |
asChild Render as a different element type. | boolean | |
disabled | boolean |
depth | number | |
id | string | |
asChild Render as a different element type. | boolean | |
disabled | boolean |
depth | number | |
id | string | |
asChild Render as a different element type. | boolean | |
disabled | boolean |
depth | number | |
id | string | |
asChild Render as a different element type. | boolean | |
disabled | boolean |
depth | number | |
id | string | |
asChild Render as a different element type. | boolean | |
disabled | boolean |