Build · New

Tree View

Shows nested content, like folders of statements or a chart of accounts, and lets people open and close branches. Each level is indented one step; files sit under their folder.

Preview

Mirrored is the same English content laid out right to left: it separates a mirroring bug from a translation one.

Installation

SoonInstalling from the registry opens at launch. Until then the command below is what it will be.
npx shadcn@latest add @ritla/tree-view

Dependencies it brings: @phosphor-icons/react

Usage

import { TreeView } from "@/components/ui/tree-view";
<TreeView
  aria-label="Documents"
  items={[
    { id: "statements", label: "Statements", children: [{ id: "q1", label: "Q1 2026" }] },
    { id: "invoices", label: "Invoices", children: [] },
  ]}
  defaultExpanded={["statements"]}
/>

Examples

Controlled selection

selected and expanded from the page: picking a file opens it beside the tree. Icons are off (showIcons={false}).

API reference

TreeView

PropTypeDefaultDescription
items{ id, label, children? }[]The tree; an item with children is a branch, even when they're empty.
expanded / defaultExpandedstring[]The open branches.
onExpandedChange(ids: string[]) => voidCalled when a branch opens or closes.
selected / defaultSelectedstring | nullThe selected row.
onSelectedChange(id: string) => voidCalled when a row is selected.
showIconsbooleantrueFigma's Show icon: the folder and file icons.
aria-labelstringThe tree's name for screen readers.

Accessibility

Keyboard

Keys are written for left-to-right. In right-to-left the arrow keys swap: the one pointing toward the reading direction moves forward.

KeyAction
TabEnters the tree once, on the selected row.
ArrowDownArrowUpBetween the visible rows.
ArrowRightOpens a closed branch, or moves to its first child. ArrowLeft in Arabic.
ArrowLeftCloses an open branch, or moves to the parent. ArrowRight in Arabic.
HomeEndTo the first or last row.
EnterSpaceSelects the row.

ARIA

  • A named role="tree"; each row is a treeitem with aria-level, aria-setsize, aria-posinset, aria-expanded on branches and aria-selected.
  • Don't go deeper than four levels, and don't use a tree to move between app sections.

Arabic and RTL notes

Mirrors

  • Indents come from the right, a closed caret points left, and the selected bar sits on the right.
  • The open and close keys flip: ArrowLeft opens, ArrowRight closes.

Does not mirror

  • The folder and file icons.
Numerals
Numbers in labels stay as written.
Arabic typography
label-14 Regular; long labels truncate with an ellipsis.
Mixed-direction text
File extensions like .pdf reorder inside an Arabic label; drop them or put them in <bdi>.

All components ›