Talisman LogoTalisman Logo Design System
Browse documentation
Components

Tree view

A hierarchical list that expands and collapses, for navigating nested structures such as the documents of a case.

Stableimport { TreeView } from "@repo/ui/tree-view";Source

Select a folder to open it. With a folder focused, ArrowRight opens it, ArrowLeft closes it and Enter or Space toggles it.

When to use

  • To browse nested content with a clear hierarchy: pastas and documentos of a case, cliente and processos.
  • When the operator needs to see where an item sits in the structure.

When not to use

  • A flat list. Use List.
  • Records with the same columns. Use Table.
  • Choosing a document from a tree inside a form. Use Document tree combobox.
  • Primary navigation of the product. Use the navigation components.

Sizes

variant sets the text size of every item in the tree.

Variant Text size Use for
sm 12px Dense side panels.
md 14px Default.
lg 24px Large, sparse structures.

Examples

From data

TreeViewGroup renders a tree from an array of { id, label, leftContent, rightContent, disabled, children }. A disabled item cannot be opened.

Composed

Use TreeViewItem directly when an item needs custom content, such as a Tag. Pass level to indent children, and defaultExpanded to start open.

Content

  • Labels are the names people use: “Petição inicial.pdf”, not an internal id.
  • Put a count or a status in rightContent, and an icon in leftContent.
  • Keep the hierarchy shallow. Past three levels, the labels are cut and hard to scan.

Accessibility

  • The root has role="tree" and each item is wrapped in role="treeitem" with aria-expanded when it has children.
  • Each item has a button. Enter and Space toggle it, ArrowRight opens it and ArrowLeft closes it.
  • A tooltip shows the full label on hover and focus, for labels that are cut.
  • Decorative icons in leftContent need aria-hidden.
  • ArrowUp and ArrowDown do not move between items. Use Tab to move through the visible items.
  • Selection is not exposed: items do not set aria-selected.

Code

import { TreeView, TreeViewGroup } from "@repo/ui/tree-view";
import type { TreeViewItemData } from "@repo/ui/tree-view";

const items: TreeViewItemData[] = [
  {
    children: [
      { id: "peticao-inicial", label: "Petição inicial.pdf" },
      { id: "procuracao", label: "Procuração.pdf" },
    ],
    id: "autos",
    label: "Autos",
  },
  { id: "sentenca", label: "Sentença.pdf" },
];

<TreeView>
  <TreeViewGroup items={items} />
</TreeView>;

Props

TreeView
PropTypeDefaultDescription
defaultExpandedstring[][]Ids of the items expanded on first render. Not read by `TreeViewItem`: use `defaultExpanded` on the item
variant"lg" | "md" | "sm"mdText size of every item in the tree
TreeView, more props
PropTypeDefaultDescription
expanded / onExpandedChangestring[] / (ids: string[]) => void—Controlled open items. Not used by `TreeViewItem` today, see Known issues.
selected / defaultSelected / onSelectedChangestring | null / (id: string | null) => void—Selected item. Not used by `TreeViewItem` today, see Known issues.
classNamestring—Extra class on the tree container.
TreeViewItem
PropTypeDefaultDescription
idstring—Identifier of the item. Required.
labelReactNode—Text of the item. Required. It is also shown in the tooltip.
leftContentReactNode—Content before the label, such as an icon.
rightContentReactNode—Content after the label, such as a count or a Tag.
levelnumber0Depth of the item. Sets the indent. `TreeViewGroup` sets it for you.
defaultExpandedbooleanfalseStarts the item open.
disabledboolean—Prevents interaction with the item.
childrenReactNode—Nested items. Their presence adds the chevron.
TreeViewGroup
PropTypeDefaultDescription
itemsTreeViewItemData[]—Items to render, with optional `children`.
levelnumber0Starting depth.
renderItem(item, level, defaultRender) => ReactNode—Custom render of one item.

Known issues

Issue Effect
TreeViewItem keeps its own open state and never calls the tree’s toggleExpanded or selectItem. expanded, onExpandedChange, selected, defaultExpanded and onSelectedChange on TreeView have no effect. There is no way to know or control the selection.
Every item has mb-6 (24px) under a 32px row. Rows are 56px apart, much more than the row height.
The treeitem wrapper has tabIndex={0} and the button inside has it too. Two tab stops per item. There is no arrow-key movement between items.
A disabled item only gets the disabled attribute. treeViewItemVariants has no disabled style. A disabled item looks the same as an enabled one.
Children are not wrapped in role="group", and items do not set aria-selected. Screen readers do not get the tree structure or the selection.
Every item renders its own TooltipProvider and tooltip. A tooltip with the label shows even when the label is not cut.
Edit this page on GitHub