Powerful and customizable React tree view components built for modern applications. These tree views are built using React Aria and styled with Tailwind CSS.
Installation
You can add this tree view component using our CLI or manually:
npx untitledui@latest add tree-view
Tree view examples
Below are examples and variations of this tree view component:
Advanced
The advanced tree view supports multi-selection, drag-and-drop reordering, connector lines, and custom icons per item.
API reference
Import the parts and assemble them:
import { TreeView } from "@/components/application/tree-view/tree-view"; <TreeView> <TreeView.Item> <TreeView.ItemContent /> <TreeView.Item> <TreeView.ItemContent /> </TreeView.Item> </TreeView.Item> </TreeView>
TreeView
Renders React Aria’s Tree — all of its props are supported.
Props from React Aria (30)
Also accepts the global HTML attributes (dir, lang, hidden, inert, translate), all standard React DOM event handlers.
TreeView.DropIndicator
Renders React Aria’s DropIndicator — all of its props are supported.
TreeView.Item
Renders React Aria’s TreeItem — all of its props are supported.
Styling (3)
Accessibility (1)
Also accepts the global HTML attributes (dir, lang, hidden, inert, translate), all standard React DOM event handlers.
TreeView.ItemContent
Renders React Aria’s TreeItemContent — all of its props are supported.
FAQs
Please refer to our frequently asked questions page for more.
A tree view consists of TreeView (the root), TreeView.Item (a node, which nests child TreeView.Item elements for its children), TreeView.ItemContent (the visible row, with an optional leading icon and a trailing action slot), and TreeView.DropIndicator (the line marking the drop position during a drag), which TreeView renders for you automatically when draggable is set.
TreeView passes its props to React Aria's Tree, so use defaultExpandedKeys to open nodes on first render, as the examples on this page do, or expandedKeys with onExpandedChange to control expansion yourself. The keys are the id values of your TreeView.Item elements.
Pass selectionMode="multiple" to the TreeView component, which adds a checkbox to every row. Selected keys can be controlled with selectedKeys and onSelectionChange, or uncontrolled with defaultSelectedKeys. Selection cascades, which React Aria does not do on its own: selecting a parent selects all of its descendants, deselecting a parent deselects them, and a parent with only some of its descendants selected renders an indeterminate checkbox. Because of that, onSelectionChange is called with the full cascaded set of keys rather than just the row the user clicked.
Pass draggable to TreeView and handle the drop yourself. onReorder fires for drops with a dropPosition of "before" or "after", and onMove fires for drops "on" another item. The Advanced examples keep the data in React Aria's useTreeData and call tree.moveBefore, tree.moveAfter and tree.move from those callbacks. The drag handle only appears on selected rows. To take over drag and drop completely, pass your own dragAndDropHooks.
Add the showConnectors prop to TreeView. It defaults to false, and when it is on, each row draws vertical lines for its ancestor levels so the hierarchy is easier to follow, as in the Advanced examples.
The tree view supports "sm" and "md" via the size prop on TreeView, with "sm" as the default. "md" adds vertical padding to each row and uses size-5 icons instead of size-4.