filter((e.currentTarget as HTMLInputElement).value)" />
```
#### Svelte
```svelte
filter(e.currentTarget.value)} />
{#each collection.rootNode.children ?? [] as node, index (node.id)}
{@render renderNode(node, [index])}
{/each}
{#snippet renderNode(node: Node, indexPath: number[])}
{#if node.children}
{node.name}
{#each node.children as child, index (child.id)}
{@render renderNode(child, [...indexPath, index])}
{/each}
{:else}
{node.name}
{/if}
{/snippet}
```
### Links
Tree items can be rendered as links to another page or website. This could be useful for documentation sites.
Here's an example that modifies the tree collection to represent an hierarchical link structure. It uses the `asChild`
prop to render the tree items as links, passing the `href` prop to a `` element.
**Example: links**
#### React
```tsx
import { TreeView, createTreeCollection } from '@ark-ui/react/tree-view'
import { ChevronRightIcon, ExternalLinkIcon, FileIcon } from 'lucide-react'
export const Links = () => {
return (
Docs
{collection.rootNode.children?.map((node, index) => (
))}
)
}
const TreeNode = (props: TreeView.NodeProviderProps) => {
const { node, indexPath } = props
return (
{node.children ? (
{node.name}
{node.children.map((child, index) => (
))}
) : (
{node.name}
{node.href?.startsWith('http') && }
)}
)
}
interface Node {
id: string
name: string
href?: string
children?: Node[]
}
const collection = createTreeCollection({
nodeToValue: (node) => node.id,
nodeToString: (node) => node.name,
rootNode: {
id: 'ROOT',
name: '',
children: [
{
id: 'docs',
name: 'Documentation',
children: [
{ id: 'docs/getting-started', name: 'Getting Started', href: '/docs/getting-started' },
{ id: 'docs/installation', name: 'Installation', href: '/docs/installation' },
{
id: 'docs/components',
name: 'Components',
children: [
{ id: 'docs/components/accordion', name: 'Accordion', href: '/docs/components/accordion' },
{ id: 'docs/components/dialog', name: 'Dialog', href: '/docs/components/dialog' },
{ id: 'docs/components/menu', name: 'Menu', href: '/docs/components/menu' },
],
},
],
},
{
id: 'examples',
name: 'Examples',
children: [
{ id: 'examples/react', name: 'React Examples', href: '/examples/react' },
{ id: 'examples/vue', name: 'Vue Examples', href: '/examples/vue' },
{ id: 'examples/solid', name: 'Solid Examples', href: '/examples/solid' },
],
},
{
id: 'external',
name: 'External Links',
children: [
{ id: 'external/github', name: 'GitHub Repository', href: 'https://github.com/chakra-ui/zag' },
{ id: 'external/npm', name: 'NPM Package', href: 'https://www.npmjs.com/package/@zag-js/core' },
{ id: 'external/docs', name: 'Official Docs', href: 'https://zagjs.com' },
],
},
{ id: 'readme.md', name: 'README.md', href: '/readme' },
{ id: 'license', name: 'LICENSE', href: '/license' },
],
},
})
```
#### Solid
```tsx
import { TreeView, createTreeCollection } from '@ark-ui/solid/tree-view'
import { ChevronRightIcon, ExternalLinkIcon, FileIcon } from 'lucide-solid'
import { For, Show } from 'solid-js'
export const Links = () => {
return (
Docs{(node, index) => }
)
}
const TreeNode = (props: TreeView.NodeProviderProps) => {
const { node, indexPath } = props
return (
}>
{node.name}
}
>
{node.name}
{(child, index) => }
)
}
interface Node {
id: string
name: string
href?: string
children?: Node[]
}
const collection = createTreeCollection({
nodeToValue: (node) => node.id,
nodeToString: (node) => node.name,
rootNode: {
id: 'ROOT',
name: '',
children: [
{
id: 'docs',
name: 'Documentation',
children: [
{ id: 'docs/getting-started', name: 'Getting Started', href: '/docs/getting-started' },
{ id: 'docs/installation', name: 'Installation', href: '/docs/installation' },
{
id: 'docs/components',
name: 'Components',
children: [
{ id: 'docs/components/accordion', name: 'Accordion', href: '/docs/components/accordion' },
{ id: 'docs/components/dialog', name: 'Dialog', href: '/docs/components/dialog' },
{ id: 'docs/components/menu', name: 'Menu', href: '/docs/components/menu' },
],
},
],
},
{
id: 'examples',
name: 'Examples',
children: [
{ id: 'examples/react', name: 'React Examples', href: '/examples/react' },
{ id: 'examples/vue', name: 'Vue Examples', href: '/examples/vue' },
{ id: 'examples/solid', name: 'Solid Examples', href: '/examples/solid' },
],
},
{
id: 'external',
name: 'External Links',
children: [
{ id: 'external/github', name: 'GitHub Repository', href: 'https://github.com/chakra-ui/zag' },
{ id: 'external/npm', name: 'NPM Package', href: 'https://www.npmjs.com/package/@zag-js/core' },
{ id: 'external/docs', name: 'Official Docs', href: 'https://zagjs.com' },
],
},
{ id: 'readme.md', name: 'README.md', href: '/readme' },
{ id: 'license', name: 'LICENSE', href: '/license' },
],
},
})
```
#### Vue
```vue
Docs
```
#### Svelte
```svelte
Docs
{#each collection.rootNode.children ?? [] as node, index (node.id)}
{/each}
```
## Guides
### Type-Safety
The `TreeView.RootComponent` type enables you to create closed, strongly typed wrapper components that maintain full type
safety for tree nodes.
This is particularly useful when building reusable tree view components with custom props and consistent styling.
```tsx
import { TreeView as ArkTreeView, type TreeNode } from '@ark-ui/react/tree-view'
import { createTreeCollection } from '@ark-ui/react/collection'
interface TreeViewProps extends ArkTreeView.RootProps {}
const TreeView: ArkTreeView.RootComponent = (props) => {
return {/* ... */}
}
```
Then, you can use the `TreeView` component as follows:
```tsx
const App = () => {
const collection = createTreeCollection({
initialItems: [
{ id: '1', label: 'React', children: [] },
{ id: '2', label: 'Vue', children: [] },
{ id: '3', label: 'Svelte', children: [] },
],
})
return (
{
// this will be strongly typed Array<{ id: string, label: string, children: [] }>
console.log(e.value)
}}
>
{/* ... */}
)
}
```
## API Reference
### Props
**Component API Reference**
#### React
**Root Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `collection` | `TreeCollection` | Yes | The collection of tree nodes |
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `checkedValue` | `string[]` | No | The controlled checked node value |
| `defaultCheckedValue` | `string[]` | No | The initial checked node value when rendered.
Use when you don't need to control the checked node value. |
| `defaultExpandedValue` | `string[]` | No | The initial expanded node ids when rendered.
Use when you don't need to control the expanded node value. |
| `defaultFocusedValue` | `string` | No | The initial focused node value when rendered.
Use when you don't need to control the focused node value. |
| `defaultSelectedValue` | `string[]` | No | The initial selected node value when rendered.
Use when you don't need to control the selected node value. |
| `expandedValue` | `string[]` | No | The controlled expanded node ids |
| `expandOnClick` | `boolean` | No | Whether clicking on a branch should open it or not |
| `focusedValue` | `string` | No | The value of the focused node |
| `ids` | `Partial<{ root: string; tree: string; label: string; node: (value: string) => string }>` | No | The ids of the tree elements. Useful for composition. |
| `lazyMount` | `boolean` | No | Whether to enable lazy mounting |
| `loadChildren` | `(details: LoadChildrenDetails) => Promise` | No | Function to load children for a node asynchronously.
When provided, branches will wait for this promise to resolve before expanding. |
| `onCheckedChange` | `(details: CheckedChangeDetails) => void` | No | Called when the checked value changes |
| `onExpandedChange` | `(details: ExpandedChangeDetails) => void` | No | Called when the tree is opened or closed |
| `onFocusChange` | `(details: FocusChangeDetails) => void` | No | Called when the focused node changes |
| `onLoadChildrenComplete` | `(details: LoadChildrenCompleteDetails) => void` | No | Called when a node finishes loading children |
| `onLoadChildrenError` | `(details: LoadChildrenErrorDetails) => void` | No | Called when loading children fails for one or more nodes |
| `onSelectionChange` | `(details: SelectionChangeDetails) => void` | No | Called when the selection changes |
| `selectedValue` | `string[]` | No | The controlled selected node value |
| `selectionMode` | `'multiple' | 'single'` | No | Whether the tree supports multiple selection
- "single": only one node can be selected
- "multiple": multiple nodes can be selected |
| `typeahead` | `boolean` | No | Whether the tree supports typeahead search |
| `unmountOnExit` | `boolean` | No | Whether to unmount on exit. |
**BranchContent Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**BranchContent Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-content |
| `[data-state]` | "open" | "closed" |
| `[data-depth]` | The depth of the item |
| `[data-path]` | The path of the item |
| `[data-value]` | The value of the item |
**BranchControl Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**BranchControl Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-control |
| `[data-path]` | The path of the item |
| `[data-state]` | "open" | "closed" |
| `[data-disabled]` | Present when disabled |
| `[data-selected]` | Present when selected |
| `[data-focus]` | Present when focused |
| `[data-value]` | The value of the item |
| `[data-depth]` | The depth of the item |
| `[data-loading]` | Present when loading |
**BranchIndentGuide Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**BranchIndentGuide Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-indent-guide |
| `[data-depth]` | The depth of the item |
**BranchIndicator Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**BranchIndicator Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-indicator |
| `[data-state]` | "open" | "closed" |
| `[data-disabled]` | Present when disabled |
| `[data-selected]` | Present when selected |
| `[data-focus]` | Present when focused |
| `[data-loading]` | Present when loading |
**Branch Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**Branch Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch |
| `[data-depth]` | The depth of the item |
| `[data-branch]` | |
| `[data-value]` | The value of the item |
| `[data-path]` | The path of the item |
| `[data-selected]` | Present when selected |
| `[data-state]` | "open" | "closed" |
| `[data-disabled]` | Present when disabled |
| `[data-loading]` | Present when loading |
**BranchText Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**BranchText Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-text |
| `[data-disabled]` | Present when disabled |
| `[data-state]` | "open" | "closed" |
| `[data-loading]` | Present when loading |
**BranchTrigger Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**BranchTrigger Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-trigger |
| `[data-disabled]` | Present when disabled |
| `[data-state]` | "open" | "closed" |
| `[data-value]` | The value of the item |
| `[data-loading]` | Present when loading |
**ItemIndicator Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**ItemIndicator Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | item-indicator |
| `[data-disabled]` | Present when disabled |
| `[data-selected]` | Present when selected |
| `[data-focus]` | Present when focused |
**Item Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**Item Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | item |
| `[data-path]` | The path of the item |
| `[data-value]` | The value of the item |
| `[data-focus]` | Present when focused |
| `[data-selected]` | Present when selected |
| `[data-disabled]` | Present when disabled |
| `[data-depth]` | The depth of the item |
**ItemText Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**ItemText Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | item-text |
| `[data-disabled]` | Present when disabled |
| `[data-selected]` | Present when selected |
| `[data-focus]` | Present when focused |
**Label Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**NodeCheckboxIndicator Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `fallback` | `string | number | bigint | boolean | ReactElement> | Iterable | ReactPortal | Promise<...>` | No | |
| `indeterminate` | `string | number | bigint | boolean | ReactElement> | Iterable | ReactPortal | Promise<...>` | No | |
**NodeCheckbox Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**NodeCheckbox Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | node-checkbox |
| `[data-state]` | "checked" | "unchecked" | "indeterminate" |
| `[data-disabled]` | Present when disabled |
**NodeProvider Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `indexPath` | `number[]` | Yes | The index path of the tree node |
| `node` | `NonNullable` | No | The tree node |
**RootProvider Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `value` | `UseTreeViewReturn` | Yes | |
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `lazyMount` | `boolean` | No | Whether to enable lazy mounting |
| `unmountOnExit` | `boolean` | No | Whether to unmount on exit. |
**Tree Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
#### Solid
**Root Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `collection` | `TreeCollection` | Yes | The collection of tree nodes |
| `asChild` | `(props: ParentProps<'div'>) => Element` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `checkedValue` | `string[]` | No | The controlled checked node value |
| `defaultCheckedValue` | `string[]` | No | The initial checked node value when rendered.
Use when you don't need to control the checked node value. |
| `defaultExpandedValue` | `string[]` | No | The initial expanded node ids when rendered.
Use when you don't need to control the expanded node value. |
| `defaultFocusedValue` | `string` | No | The initial focused node value when rendered.
Use when you don't need to control the focused node value. |
| `defaultSelectedValue` | `string[]` | No | The initial selected node value when rendered.
Use when you don't need to control the selected node value. |
| `expandedValue` | `string[]` | No | The controlled expanded node ids |
| `expandOnClick` | `boolean` | No | Whether clicking on a branch should open it or not |
| `focusedValue` | `string` | No | The value of the focused node |
| `id` | `string` | No | The unique identifier of the machine. |
| `ids` | `Partial<{ root: string; tree: string; label: string; node: (value: string) => string }>` | No | The ids of the tree elements. Useful for composition. |
| `lazyMount` | `boolean` | No | Whether to enable lazy mounting |
| `loadChildren` | `(details: LoadChildrenDetails) => Promise` | No | Function to load children for a node asynchronously.
When provided, branches will wait for this promise to resolve before expanding. |
| `onCheckedChange` | `(details: CheckedChangeDetails) => void` | No | Called when the checked value changes |
| `onExpandedChange` | `(details: ExpandedChangeDetails) => void` | No | Called when the tree is opened or closed |
| `onFocusChange` | `(details: FocusChangeDetails) => void` | No | Called when the focused node changes |
| `onLoadChildrenComplete` | `(details: LoadChildrenCompleteDetails) => void` | No | Called when a node finishes loading children |
| `onLoadChildrenError` | `(details: LoadChildrenErrorDetails) => void` | No | Called when loading children fails for one or more nodes |
| `onSelectionChange` | `(details: SelectionChangeDetails) => void` | No | Called when the selection changes |
| `selectedValue` | `string[]` | No | The controlled selected node value |
| `selectionMode` | `'multiple' | 'single'` | No | Whether the tree supports multiple selection
- "single": only one node can be selected
- "multiple": multiple nodes can be selected |
| `typeahead` | `boolean` | No | Whether the tree supports typeahead search |
| `unmountOnExit` | `boolean` | No | Whether to unmount on exit. |
**BranchContent Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `(props: ParentProps<'div'>) => Element` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**BranchContent Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-content |
| `[data-state]` | "open" | "closed" |
| `[data-depth]` | The depth of the item |
| `[data-path]` | The path of the item |
| `[data-value]` | The value of the item |
**BranchControl Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `(props: ParentProps<'div'>) => Element` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**BranchControl Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-control |
| `[data-path]` | The path of the item |
| `[data-state]` | "open" | "closed" |
| `[data-disabled]` | Present when disabled |
| `[data-selected]` | Present when selected |
| `[data-focus]` | Present when focused |
| `[data-value]` | The value of the item |
| `[data-depth]` | The depth of the item |
| `[data-loading]` | Present when loading |
**BranchIndentGuide Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `(props: ParentProps<'div'>) => Element` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**BranchIndentGuide Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-indent-guide |
| `[data-depth]` | The depth of the item |
**BranchIndicator Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `(props: ParentProps<'div'>) => Element` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**BranchIndicator Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-indicator |
| `[data-state]` | "open" | "closed" |
| `[data-disabled]` | Present when disabled |
| `[data-selected]` | Present when selected |
| `[data-focus]` | Present when focused |
| `[data-loading]` | Present when loading |
**Branch Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `(props: ParentProps<'div'>) => Element` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**Branch Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch |
| `[data-depth]` | The depth of the item |
| `[data-branch]` | |
| `[data-value]` | The value of the item |
| `[data-path]` | The path of the item |
| `[data-selected]` | Present when selected |
| `[data-state]` | "open" | "closed" |
| `[data-disabled]` | Present when disabled |
| `[data-loading]` | Present when loading |
**BranchText Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `(props: ParentProps<'span'>) => Element` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**BranchText Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-text |
| `[data-disabled]` | Present when disabled |
| `[data-state]` | "open" | "closed" |
| `[data-loading]` | Present when loading |
**BranchTrigger Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `(props: ParentProps<'div'>) => Element` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**BranchTrigger Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-trigger |
| `[data-disabled]` | Present when disabled |
| `[data-state]` | "open" | "closed" |
| `[data-value]` | The value of the item |
| `[data-loading]` | Present when loading |
**ItemIndicator Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `(props: ParentProps<'div'>) => Element` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**ItemIndicator Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | item-indicator |
| `[data-disabled]` | Present when disabled |
| `[data-selected]` | Present when selected |
| `[data-focus]` | Present when focused |
**Item Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `(props: ParentProps<'div'>) => Element` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**Item Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | item |
| `[data-path]` | The path of the item |
| `[data-value]` | The value of the item |
| `[data-focus]` | Present when focused |
| `[data-selected]` | Present when selected |
| `[data-disabled]` | Present when disabled |
| `[data-depth]` | The depth of the item |
**ItemText Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `(props: ParentProps<'span'>) => Element` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**ItemText Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | item-text |
| `[data-disabled]` | Present when disabled |
| `[data-selected]` | Present when selected |
| `[data-focus]` | Present when focused |
**Label Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `(props: ParentProps<'h3'>) => Element` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**NodeCheckboxIndicator Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `fallback` | `number | boolean | Node | (string & {}) | ArrayElement` | No | |
| `indeterminate` | `number | boolean | Node | (string & {}) | ArrayElement` | No | |
**NodeCheckbox Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `(props: ParentProps<'span'>) => Element` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**NodeCheckbox Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | node-checkbox |
| `[data-state]` | "checked" | "unchecked" | "indeterminate" |
| `[data-disabled]` | Present when disabled |
**NodeProvider Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `indexPath` | `number[]` | Yes | The index path of the tree node |
| `node` | `NonNullable` | No | The tree node |
**RootProvider Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `value` | `UseTreeViewReturn` | Yes | |
| `asChild` | `(props: ParentProps<'div'>) => Element` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `lazyMount` | `boolean` | No | Whether to enable lazy mounting |
| `unmountOnExit` | `boolean` | No | Whether to unmount on exit. |
**Tree Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `(props: ParentProps<'div'>) => Element` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
#### Vue
**Root Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `collection` | `TreeCollection` | Yes | The collection of tree nodes |
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `checkedValue` | `string[]` | No | The controlled checked node values |
| `defaultCheckedValue` | `string[]` | No | The initial checked node values when rendered.
Use when you don't need to control the checked node values. |
| `defaultExpandedValue` | `string[]` | No | The initial expanded node values when rendered.
Use when you don't need to control the expanded node values. |
| `defaultFocusedValue` | `string` | No | The initial focused node value when rendered.
Use when you don't need to control the focused node value. |
| `defaultSelectedValue` | `string[]` | No | The initial selected node values when rendered.
Use when you don't need to control the selected node values. |
| `expandedValue` | `string[]` | No | The controlled expanded node values |
| `expandOnClick` | `boolean` | No | Whether clicking on a branch should open it or not |
| `focusedValue` | `string` | No | The id of the focused node |
| `id` | `string` | No | The unique identifier of the machine. |
| `ids` | `Partial<{ root: string; tree: string; label: string; node(value: string): string }>` | No | The ids of the tree elements. Useful for composition. |
| `lazyMount` | `boolean` | No | Whether to enable lazy mounting |
| `loadChildren` | `(details: LoadChildrenDetails) => Promise` | No | A function that loads the children of a node. |
| `selectedValue` | `string[]` | No | The controlled selected node values |
| `selectionMode` | `'multiple' | 'single'` | No | Whether the tree supports multiple selection
- "single": only one node can be selected
- "multiple": multiple nodes can be selected |
| `typeahead` | `boolean` | No | Whether the tree supports typeahead search |
| `unmountOnExit` | `boolean` | No | Whether to unmount on exit. |
**BranchContent Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**BranchContent Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-content |
| `[data-state]` | "open" | "closed" |
| `[data-depth]` | The depth of the item |
| `[data-path]` | The path of the item |
| `[data-value]` | The value of the item |
**BranchControl Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**BranchControl Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-control |
| `[data-path]` | The path of the item |
| `[data-state]` | "open" | "closed" |
| `[data-disabled]` | Present when disabled |
| `[data-selected]` | Present when selected |
| `[data-focus]` | Present when focused |
| `[data-value]` | The value of the item |
| `[data-depth]` | The depth of the item |
| `[data-loading]` | Present when loading |
**BranchIndentGuide Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**BranchIndentGuide Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-indent-guide |
| `[data-depth]` | The depth of the item |
**BranchIndicator Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**BranchIndicator Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-indicator |
| `[data-state]` | "open" | "closed" |
| `[data-disabled]` | Present when disabled |
| `[data-selected]` | Present when selected |
| `[data-focus]` | Present when focused |
| `[data-loading]` | Present when loading |
**Branch Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**Branch Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch |
| `[data-depth]` | The depth of the item |
| `[data-branch]` | |
| `[data-value]` | The value of the item |
| `[data-path]` | The path of the item |
| `[data-selected]` | Present when selected |
| `[data-state]` | "open" | "closed" |
| `[data-disabled]` | Present when disabled |
| `[data-loading]` | Present when loading |
**BranchText Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**BranchText Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-text |
| `[data-disabled]` | Present when disabled |
| `[data-state]` | "open" | "closed" |
| `[data-loading]` | Present when loading |
**BranchTrigger Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**BranchTrigger Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-trigger |
| `[data-disabled]` | Present when disabled |
| `[data-state]` | "open" | "closed" |
| `[data-value]` | The value of the item |
| `[data-loading]` | Present when loading |
**ItemIndicator Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**ItemIndicator Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | item-indicator |
| `[data-disabled]` | Present when disabled |
| `[data-selected]` | Present when selected |
| `[data-focus]` | Present when focused |
**Item Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**Item Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | item |
| `[data-path]` | The path of the item |
| `[data-value]` | The value of the item |
| `[data-focus]` | Present when focused |
| `[data-selected]` | Present when selected |
| `[data-disabled]` | Present when disabled |
| `[data-depth]` | The depth of the item |
**ItemText Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**ItemText Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | item-text |
| `[data-disabled]` | Present when disabled |
| `[data-selected]` | Present when selected |
| `[data-focus]` | Present when focused |
**Label Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**NodeCheckboxIndicator Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `fallback` | `{}` | No | |
| `indeterminate` | `{}` | No | |
**NodeCheckbox Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
**NodeCheckbox Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | node-checkbox |
| `[data-state]` | "checked" | "unchecked" | "indeterminate" |
| `[data-disabled]` | Present when disabled |
**NodeProvider Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `indexPath` | `number[]` | Yes | The index path of the tree node |
| `node` | `NonNullable` | No | The tree node |
**RootProvider Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `value` | `TreeViewApi` | Yes | |
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `lazyMount` | `boolean` | No | Whether to enable lazy mounting |
| `unmountOnExit` | `boolean` | No | Whether to unmount on exit. |
**Tree Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
#### Svelte
**Root Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `Snippet<[PropsFn<'div'>]>` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `checkedValue` | `string[]` | No | The controlled checked node value |
| `collection` | `TreeCollection` | No | The tree collection data |
| `defaultCheckedValue` | `string[]` | No | The initial checked node value when rendered.
Use when you don't need to control the checked node value. |
| `defaultExpandedValue` | `string[]` | No | The initial expanded node ids when rendered.
Use when you don't need to control the expanded node value. |
| `defaultFocusedValue` | `string` | No | The initial focused node value when rendered.
Use when you don't need to control the focused node value. |
| `defaultSelectedValue` | `string[]` | No | The initial selected node value when rendered.
Use when you don't need to control the selected node value. |
| `expandedValue` | `string[]` | No | The controlled expanded node ids |
| `expandOnClick` | `boolean` | No | Whether clicking on a branch should open it or not |
| `focusedValue` | `string` | No | The value of the focused node |
| `id` | `string` | No | The unique identifier of the machine. |
| `ids` | `Partial<{ root: string; tree: string; label: string; node: (value: string) => string }>` | No | The ids of the tree elements. Useful for composition. |
| `lazyMount` | `boolean` | No | Whether to enable lazy mounting |
| `loadChildren` | `(details: LoadChildrenDetails) => Promise` | No | Function to load children for a node asynchronously.
When provided, branches will wait for this promise to resolve before expanding. |
| `onCheckedChange` | `(details: CheckedChangeDetails) => void` | No | Called when the checked value changes |
| `onExpandedChange` | `(details: ExpandedChangeDetails) => void` | No | Called when the tree is opened or closed |
| `onFocusChange` | `(details: FocusChangeDetails) => void` | No | Called when the focused node changes |
| `onLoadChildrenComplete` | `(details: LoadChildrenCompleteDetails) => void` | No | Called when a node finishes loading children |
| `onLoadChildrenError` | `(details: LoadChildrenErrorDetails) => void` | No | Called when loading children fails for one or more nodes |
| `onSelectionChange` | `(details: SelectionChangeDetails) => void` | No | Called when the selection changes |
| `ref` | `Element` | No | |
| `selectedValue` | `string[]` | No | The controlled selected node value |
| `selectionMode` | `'multiple' | 'single'` | No | Whether the tree supports multiple selection
- "single": only one node can be selected
- "multiple": multiple nodes can be selected |
| `typeahead` | `boolean` | No | Whether the tree supports typeahead search |
| `unmountOnExit` | `boolean` | No | Whether to unmount on exit. |
**BranchContent Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `Snippet<[PropsFn<'ul'>]>` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `ref` | `Element` | No | |
**BranchContent Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-content |
| `[data-state]` | "open" | "closed" |
| `[data-depth]` | The depth of the item |
| `[data-path]` | The path of the item |
| `[data-value]` | The value of the item |
**BranchControl Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `Snippet<[PropsFn<'div'>]>` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `ref` | `Element` | No | |
**BranchControl Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-control |
| `[data-path]` | The path of the item |
| `[data-state]` | "open" | "closed" |
| `[data-disabled]` | Present when disabled |
| `[data-selected]` | Present when selected |
| `[data-focus]` | Present when focused |
| `[data-value]` | The value of the item |
| `[data-depth]` | The depth of the item |
| `[data-loading]` | Present when loading |
**BranchIndentGuide Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `Snippet<[PropsFn<'div'>]>` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `ref` | `Element` | No | |
**BranchIndentGuide Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-indent-guide |
| `[data-depth]` | The depth of the item |
**BranchIndicator Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `Snippet<[PropsFn<'div'>]>` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `ref` | `Element` | No | |
**BranchIndicator Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-indicator |
| `[data-state]` | "open" | "closed" |
| `[data-disabled]` | Present when disabled |
| `[data-selected]` | Present when selected |
| `[data-focus]` | Present when focused |
| `[data-loading]` | Present when loading |
**Branch Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `Snippet<[PropsFn<'li'>]>` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `ref` | `Element` | No | |
**Branch Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch |
| `[data-depth]` | The depth of the item |
| `[data-branch]` | |
| `[data-value]` | The value of the item |
| `[data-path]` | The path of the item |
| `[data-selected]` | Present when selected |
| `[data-state]` | "open" | "closed" |
| `[data-disabled]` | Present when disabled |
| `[data-loading]` | Present when loading |
**BranchText Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `Snippet<[PropsFn<'span'>]>` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `ref` | `Element` | No | |
**BranchText Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-text |
| `[data-disabled]` | Present when disabled |
| `[data-state]` | "open" | "closed" |
| `[data-loading]` | Present when loading |
**BranchTrigger Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `Snippet<[PropsFn<'button'>]>` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `ref` | `Element` | No | |
**BranchTrigger Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | branch-trigger |
| `[data-disabled]` | Present when disabled |
| `[data-state]` | "open" | "closed" |
| `[data-value]` | The value of the item |
| `[data-loading]` | Present when loading |
**Context Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `render` | `Snippet<[UseTreeViewContext]>` | Yes | |
**ItemIndicator Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `Snippet<[PropsFn<'div'>]>` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `ref` | `Element` | No | |
**ItemIndicator Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | item-indicator |
| `[data-disabled]` | Present when disabled |
| `[data-selected]` | Present when selected |
| `[data-focus]` | Present when focused |
**Item Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `Snippet<[PropsFn<'li'>]>` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `ref` | `Element` | No | |
**Item Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | item |
| `[data-path]` | The path of the item |
| `[data-value]` | The value of the item |
| `[data-focus]` | Present when focused |
| `[data-selected]` | Present when selected |
| `[data-disabled]` | Present when disabled |
| `[data-depth]` | The depth of the item |
**ItemText Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `Snippet<[PropsFn<'span'>]>` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `ref` | `Element` | No | |
**ItemText Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | item-text |
| `[data-disabled]` | Present when disabled |
| `[data-selected]` | Present when selected |
| `[data-focus]` | Present when focused |
**Label Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `Snippet<[PropsFn<'h3'>]>` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `ref` | `Element` | No | |
**NodeCheckboxIndicator Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `fallback` | `Snippet<[]>` | No | |
| `indeterminate` | `Snippet<[]>` | No | |
**NodeCheckbox Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `Snippet<[PropsFn<'span'>]>` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `ref` | `Element` | No | |
**NodeCheckbox Data Attributes:**
| Attribute | Value |
|-----------|-------|
| `[data-scope]` | tree-view |
| `[data-part]` | node-checkbox |
| `[data-state]` | "checked" | "unchecked" | "indeterminate" |
| `[data-disabled]` | Present when disabled |
**NodeContext Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `render` | `Snippet<[UseTreeViewNodeContext]>` | Yes | |
**NodeProvider Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `indexPath` | `number[]` | Yes | |
| `node` | `NonNullable` | No | |
**RootProvider Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `value` | `UseTreeViewReturn` | Yes | |
| `asChild` | `Snippet<[PropsFn<'div'>]>` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `lazyMount` | `boolean` | No | Whether to enable lazy mounting |
| `ref` | `Element` | No | |
| `unmountOnExit` | `boolean` | No | Whether to unmount on exit. |
**Tree Props:**
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `Snippet<[PropsFn<'ul'>]>` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `ref` | `Element` | No | |
### Context
These are the properties available when using `UtreeUview.Context`, `useUtreeUviewContext` hook or `useUtreeUview` hook.
**API:**
| Property | Type | Description |
|----------|------|-------------|
| `collection` | `TreeCollection` | The tree collection data |
| `expandedValue` | `string[]` | The value of the expanded nodes. |
| `setExpandedValue` | `(value: string[]) => void` | Sets the expanded value |
| `selectedValue` | `string[]` | The value of the selected nodes. |
| `setSelectedValue` | `(value: string[]) => void` | Sets the selected value |
| `checkedValue` | `string[]` | The value of the checked nodes |
| `toggleChecked` | `(value: string, isBranch: boolean) => void` | Toggles the checked value of a node |
| `setChecked` | `(value: string[]) => void` | Sets the checked value of a node |
| `clearChecked` | `VoidFunction` | Clears the checked value of a node |
| `getCheckedMap` | `() => CheckedValueMap` | Returns the checked details of branch and leaf nodes |
| `getVisibleNodes` | `() => V[]` | Returns the visible nodes as a flat array of nodes and their index path |
| `expand` | `(value?: string[]) => void` | Function to expand nodes.
If no value is provided, all nodes will be expanded |
| `collapse` | `(value?: string[]) => void` | Function to collapse nodes
If no value is provided, all nodes will be collapsed |
| `select` | `(value?: string[]) => void` | Function to select nodes
If no value is provided, all nodes will be selected |
| `deselect` | `(value?: string[]) => void` | Function to deselect nodes
If no value is provided, all nodes will be deselected |
| `focus` | `(value: string) => void` | Function to focus a node by value |
| `selectParent` | `(value: string) => void` | Function to select the parent node of the focused node |
| `expandParent` | `(value: string) => void` | Function to expand the parent node of the focused node |
## Accessibility
Complies with the [Tree View WAI-ARIA design pattern](https://www.w3.org/WAI/ARIA/apg/patterns/treeview/).
### Keyboard Support