Tree
Installation
Add the component with the CLI.
npx shadcn@latest add @intentui/tree
Composed components
When you install this component via the CLI, it automatically loads all composed components, so you donโt need to add them individually.
Manual installation
Install the dependencies, then copy the component source into your project.
npm install react-aria-components @heroicons/react cn
Anatomy
import { Tree, TreeContent, TreeItem } from "@/components/ui/tree"<Tree aria-label="Tree anatomy example">
<TreeItem id="a" textValue="Departments">
<TreeContent />
<TreeItem id="b" textValue="Sales">
<TreeContent>Sales</TreeContent>
<TreeItem id="c" textValue="Reports">
<TreeContent>Reports</TreeContent>
<TreeItem id="d1" textValue="Q1.pdf">
<TreeContent>Q1.pdf</TreeContent>
</TreeItem>
<TreeItem id="d2" textValue="Q2.pdf">
<TreeContent>Q2.pdf</TreeContent>
</TreeItem>
<TreeItem id="q3" textValue="Q3.pdf">
<TreeContent>Q3.pdf</TreeContent>
</TreeItem>
</TreeItem>
<TreeItem id="contacts" textValue="Client Contacts">
<TreeContent>Client Contacts</TreeContent>
<TreeItem id="europe" textValue="Europe.xlsx">
<TreeContent>Europe.xlsx</TreeContent>
</TreeItem>
<TreeItem id="asia" textValue="Asia.xlsx">
<TreeContent>Asia.xlsx</TreeContent>
</TreeItem>
</TreeItem>
</TreeItem>
</TreeItem>
<TreeItem id="projects" textValue="Projects">
<TreeContent>Projects</TreeContent>
<TreeItem id="revamp" textValue="Website revamp">
<TreeContent>Website revamp</TreeContent>
<TreeItem id="wireframes" textValue="Wireframes">
<TreeContent>Wireframes</TreeContent>
<TreeItem id="home" textValue="Home.fig">
<TreeContent>Home.fig</TreeContent>
</TreeItem>
<TreeItem id="pricing" textValue="Pricing.fig">
<TreeContent>Pricing.fig</TreeContent>
</TreeItem>
</TreeItem>
</TreeItem>
<TreeItem id="mobileapp" textValue="Mobile app">
<TreeContent>Mobile app</TreeContent>
</TreeItem>
</TreeItem>
</Tree>Examples
Multiple selection
Set selectionMode="multiple" to allow multiple selections.
Like a folder tree
A tree can be used to represent a folder structure, allowing users to expand and collapse folders to view their contents.
Infinite scrolling
Load more tree items as users scroll with infinite scrolling.
Drag and drop
The tree supports drag and drop functionalities if you use the dragAndDropHooks prop along with the useDragAndDrop hook. You can drop data on the entire tree, individual items, add new items between existing ones, or rearrange items.
Component API
Tree
Tree extends the React Aria Components <Tree> component.
classNamestringTreeContent
TreeContent extends the React Aria Components <TreeItemContent> component.
classNamestringTreeIndicator
TreeIndicator extends the React Aria Components <Button> component.
valuesPick<TreeItemContentRenderProps, "isDisabled" | "isExpanded">TreeItem
TreeItem extends the React Aria Components <TreeItem> component.
classNamestringSee the React Aria for the full API reference.
