- Accordion new
- ActionSheet new
- Alert new
- Alert Dialog new
- Angle Slider new
- Autocomplete new
- Avatar new
- Badge new
- Breadcrumb new
- Button new
- Button Group new
- Card new
- Carousel new
- Checkbox new
- Clipboard new
- Collapsible new
- Color Picker new
- Date Input new
- Date Picker new
- Dialog new
- DialogCaller new
- Drawer beta
- Editable new
- Empty new
- Field new
- Fieldset new
- File Upload new
- Filters new
- Floating Panel new
- Hover Card new
- Image new
- Image Cropper new
- Input new
- Input Group new
- Json Tree View new
- Kbd new
- Listbox new
- Marquee new
- Menu new
- Number Input new
- Pagination new
- Password Input new
- PhoneField new
- Pin Input new
- Popover new
- Progress Circular new
- Progress Linear new
- Qr Code new
- Radio Group new
- Rating Group new
- Scroll Area new
- ScrollSpy new
- Segment Group new
- Select new
- Separator new
- Sidebar new
- Signature Pad new
- Skeleton new
- Slider new
- Splitter new
- Steps new
- Switch new
- Table new
- Tabs new
- Tags Input new
- Textarea new
- Timeline new
- Timer new
- Toast new
- Toc new
- Toggle new
- Toggle Group new
- Tooltip new
- Tour new
- Tree View new
- Typography new
Tree View
Vue tree view for nested folders and hierarchical data with expand, collapse, and selection.
Installation
Install from the Vuzeno registry:
bunx --bun shadcn-vue@latest add https://vuzeno.com/r/tree-view.json
npx shadcn-vue@latest add https://vuzeno.com/r/tree-view.json
yarn dlx shadcn-vue@latest add https://vuzeno.com/r/tree-view.json
pnpm dlx shadcn-vue@latest add https://vuzeno.com/r/tree-view.json
Usage
<script setup lang="ts">
import { TreeView } from "@/components/ui/tree-view";
</script>
<template>
<TreeView.Root>
<!-- … -->
</TreeView.Root>
</template>
Examples
Controlled Expanded
Pass the expandedValue and onExpandedChange props to the TreeView.Root component to control the expanded state of the tree view.
Controlled Selection
Pass the selectedValue and onSelectionChange props to the TreeView.Root component to control the selected state of the tree view.
Root Provider
An alternative way to control the tree view is to use the RootProvider component and the useTreeView hook. This way you can access the state and methods from outside the component.
Lazy Loading
Lazy loading is a feature that allows the tree view to load children of a node on demand (or async). This helps to improve the initial load time and memory usage.
To use this, you need to provide the following:
loadChildren— A function that is used to load the children of a node.onLoadChildrenComplete— A callback that is called when the children of a node are loaded. Used to update the tree collection.childrenCount— A number that indicates the number of children of a branch node.
Lazy Mount
Lazy mounting is a feature that allows the content of a tree view to be rendered only when it is expanded. This is useful for performance optimization, especially when tree content is large or complex. To enable lazy mounting, use the lazyMount prop on the TreeView.Root component.
In addition, the unmountOnExit prop can be used in conjunction with lazyMount to unmount the tree view content when branches are collapsed, freeing up resources. The next time a branch is expanded, its content will be re-rendered.
Filtering
Filtering is useful when you have a large tree and you want to filter the nodes to only show the ones that match the search query. Here's an example that composes the filter method from the TreeCollection and useFilter hook to filter the nodes.
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 <a> element.
Virtualized
For large tree views with thousands of nodes, virtualization can significantly improve performance by only rendering visible nodes.
Key implementation details:
- Use
useTreeViewhook withTreeView.RootProviderfor programmatic control - Pass
scrollToIndexFnto enable keyboard navigation within the virtualized list - Use
getVisibleNodes()to get the flattened list of currently visible nodes
Checkbox Tree
Use the defaultCheckedValue prop to enable checkbox selection mode. This allows users to select multiple nodes with checkboxes, including parent-child selection relationships.
Expand and Collapse All
Use the expand() and collapse() methods from the tree view context to programmatically expand or collapse all branches.
Mutation
Use the collection's remove() and replace() methods to dynamically add and remove nodes from the tree. This is useful for building file explorer interfaces where users can create and delete files.
Rename Node
Enable inline renaming of nodes using the canRename prop and onRenameComplete callback. Press F2 to activate rename mode on the focused node.
Composition
TreeView.Root
├── TreeView.Label
├── TreeView.Tree
│ └── TreeView.NodeProvider
│ ├── TreeView.Branch
│ │ ├── TreeView.BranchControl
│ │ │ ├── TreeView.BranchIndicator
│ │ │ └── TreeView.BranchText
│ │ └── TreeView.BranchContent
│ │ ├── TreeView.BranchIndentGuide
│ │ └── TreeView.Item
│ │ └── TreeView.ItemText
API
See Ark UI Tree View docs for full props and examples.