TreeView
Shows items that nest inside each other, like folders and files or categories, so people can open a branch and pick one item. For a flat list, use a list or a menu.
- Getting started
- Create an account
- Invite your team
- Billing
Installation
Set up Camaleo once (Installation), then import what you need. It runs on the client, because it keeps the open branches and the selection.
import { TreeView, TreeItem } from "@camaleo/react";Anatomy
A list of items, where an item with children opens a nested group. Every part has a data-slot you can target from CSS.
Examples
Every example is a real file you can copy. They all wear the skin, mode and brand from the bar above.
- src
- components
- button.tsx
- card.tsx
- index.ts
- styles
- package.json
- README.md
- Getting started
- Billing
- Change your plan
- Download invoices
Open on the current item
Open the branches that lead to the selected item with defaultExpandedValues. People see where they are without clicking, and Tab lands on that item.
- images
- hero-banner.png
- avatar-default.png
- logo-mark.svg
- fonts
Several items at once
Use selectionMode="multiple" when people act on a batch, like moving files. Space adds or removes one item and keeps the others.
- Production
- Primary database
- Read replica
- Cache
Icons for the kind of item
Pass icon when items are of different kinds, like servers and databases. The icon is hidden from screen readers, so the label must say everything.
- public1.6 MB
- hero.webp1.2 MB
- logo.svg8 kB
- favicon.ico15 kB
- package.json1.4 kB
One fact per row
Use meta for a short value, like a size or a count. Screen readers read it with the label, so keep it to a few characters.
- app
- page.tsx
- layout.tsx
- api
- package.json
Selected: app/page.tsx
React to the selection
Click a file or press Enter on it. Control selectedValues when another part of the page shows what was picked, like an editor or a preview.
- Account
- Profile
- Security
- Notifications
Named by its heading
Point aria-labelledby at the visible heading, so screen readers say what the tree holds. The tree is one Tab stop; arrow keys move inside it.
In context
Trees usually sit in a sidebar or a card, next to the content they open. These are whole pieces of UI you can copy, in the skin you picked.
Explorer
main- src
- app
- page.tsxmodified
- layout.tsx
- lib
- next.config.mjs
Categories
- Electronics296
- Computers200
- Laptops142
- Desktops58
- Audio96
- Clothing84
Mailboxes
- Inbox
- Clients
- Suppliers
- Sent
- Archive
Guidelines
- Electronics
- Computers
- Audio
- Clothing
Folders, categories and sections with subsections are what the open and close arrows are for.
- Profile
- Notifications
- Security
With no branches, the tree adds arrow keys and announcements for nothing. Use a list, links or a menu.
- src
- components
- button.tsx
- card.tsx
The branch above already says where the item is, so the label only needs its own name.
- src
- src/components
- src/components/button.tsx
- src/components/card.tsx
Long labels get cut off on narrow screens, and screen readers repeat the same words on every row.
Props
single selects one item, multiple several, none turns selection off.Every item needs a value that is unique in the whole tree, like its path: two items with the same value open and select together. TreeView also takes the attributes of <ul>, and TreeItem those of <li>.
Styling hooks
Restyle it without forking: target the attributes, or set the tokens on a parent, a skin or the tree itself.
Attributes
Tokens it reads
Color
Shape & size
This component only
Accessibility
- The tree is a role="tree" list. Branches have aria-expanded and open a role="group"; items have aria-selected, and multiple selection adds aria-multiselectable.
- Tab enters on the selected item, or on the first item when nothing selected is visible.
- Name the tree with aria-label, or aria-labelledby pointing at its heading.
- There is no type-to-find: with long lists, add a search field above the tree.