Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Data display

TreeView

Free15.2 KB gzipped

A hierarchical list (WAI-ARIA Tree View pattern) for file explorers, org charts, and nested categories. Data-driven: pass items as a tree of TreeNodes.

Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Arrow Down, Arrow Up, Arrow Right and 9 more · Full report

Import

tsx
import { TreeView } from "@vjdesigns/vjdesigns-ui";

Importing only TreeView adds about 15.2 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.

Examples

File tree

Arrow keys move and expand, typing jumps to a matching item, and icon can depend on the node's state.

  • src
    • App.tsx
    • main.tsx
  • package.json
  • README.md

Selected: app

tsx
import { useState } from "react";
import {
  FileIcon,
  FolderIcon,
  FolderOpenIcon,
  Stack,
  Text,
  TreeView,
  type TreeNode,
} from "@vjdesigns/vjdesigns-ui";

const files: TreeNode[] = [
  {
    id: "src",
    label: "src",
    children: [
      {
        id: "components",
        label: "components",
        children: [
          { id: "button", label: "Button.tsx" },
          { id: "card", label: "Card.tsx" },
        ],
      },
      { id: "app", label: "App.tsx" },
      { id: "main", label: "main.tsx" },
    ],
  },
  { id: "package", label: "package.json" },
  { id: "readme", label: "README.md" },
];

export function FileTree() {
  const [selected, setSelected] = useState<string[]>(["app"]);
  const withIcons = (nodes: TreeNode[]): TreeNode[] =>
    nodes.map((node) => ({
      ...node,
      icon: node.children ? (state) => (state.expanded ? <FolderOpenIcon /> : <FolderIcon />) : <FileIcon />,
      children: node.children && withIcons(node.children),
    }));

  return (
    <Stack gap={3} style={{ width: "100%", maxWidth: "20rem" }}>
      <TreeView
        aria-label="Project files"
        items={withIcons(files)}
        defaultExpanded={["src"]}
        selected={selected}
        onSelectedChange={setSelected}
      />
      <Text size="sm" tone="muted">
        Selected: <code>{selected.join(", ")}</code>
      </Text>
    </Stack>
  );
}

Checkboxes

checkboxes with selectionMode="multiple" gives tri-state checkboxes that cascade to children.

  • src
    • components
      • Button.tsx
      • Card.tsx
    • App.tsx
    • main.tsx
  • package.json
  • README.md
tsx
import { TreeView, type TreeNode } from "@vjdesigns/vjdesigns-ui";

const files: TreeNode[] = [
  {
    id: "src",
    label: "src",
    children: [
      {
        id: "components",
        label: "components",
        children: [
          { id: "button", label: "Button.tsx" },
          { id: "card", label: "Card.tsx" },
        ],
      },
      { id: "app", label: "App.tsx" },
      { id: "main", label: "main.tsx" },
    ],
  },
  { id: "package", label: "package.json" },
  { id: "readme", label: "README.md" },
];

export function Checkboxes() {
  return (
    <div style={{ width: "100%", maxWidth: "20rem" }}>
      <TreeView aria-label="Files to sync" items={files} selectionMode="multiple" checkboxes defaultExpanded={["src", "components"]} />
    </div>
  );
}

Accessibility

A tree is one Tab stop: arrow keys move, open and close; Home and End jump; typing jumps by name. With checkboxes, checking a folder checks everything in it, and a partly checked folder is announced as "mixed".

  • src
    • App.tsx
    • main.tsx
  • package.json
  • README.md
tsx
import { TreeView, type TreeNode } from "@vjdesigns/vjdesigns-ui";

const files: TreeNode[] = [
  {
    id: "src",
    label: "src",
    children: [
      {
        id: "components",
        label: "components",
        children: [
          { id: "button", label: "Button.tsx" },
          { id: "card", label: "Card.tsx" },
        ],
      },
      { id: "app", label: "App.tsx" },
      { id: "main", label: "main.tsx" },
    ],
  },
  { id: "package", label: "package.json" },
  { id: "readme", label: "README.md" },
];

export function Accessibility() {
  return (
    <div style={{ width: "100%", maxWidth: "22rem" }}>
      <TreeView aria-label="Folders to sync" items={files} selectionMode="multiple" checkboxes defaultExpanded={["src"]} defaultSelected={["components"]} />
    </div>
  );
}

Translated

In Hebrew the tree mirrors: nesting indents from the right, and the arrow keys that open and close folders follow the reading direction. The labels are your own text.

  • מסמכים
    • חשבוניות
    • חוזים
  • תמונות
tsx
import {
  TreeView,
  type TreeNode,
  LocaleProvider,
} from "@vjdesigns/vjdesigns-ui";
import he from "@vjdesigns/vjdesigns-ui/locales/he";

export function Translated() {
  const items: TreeNode[] = [
    {
      id: "docs",
      label: "מסמכים",
      children: [
        { id: "invoices", label: "חשבוניות" },
        { id: "contracts", label: "חוזים" },
      ],
    },
    { id: "photos", label: "תמונות" },
  ];
  return (
    <LocaleProvider locale="he" messages={he}>
      <div style={{ width: "100%", maxWidth: "22rem" }}>
        <TreeView aria-label="קבצים" items={items} defaultExpanded={["docs"]} />
      </div>
    </LocaleProvider>
  );
}

Usage notes

One tab stop (roving tabindex). Arrows move, open, and close; Home and End jump; typing jumps by name; * opens all siblings; Enter activates; Space selects. Supports single, multiple, and tri-state checkbox selection, and children loaded on demand.

tsx
<TreeView aria-label="Files" items={files} onAction={(id) => open(id)} />

API reference

TreeView

TreeView props
PropTypeDefault
itemsRequired

The nodes to show. Each node has a unique id, a label, and optional children, icon, disabled, hasChildren.

TreeNode[]—
expanded

Ids of the open parent nodes (controlled).

string[]—
defaultExpanded

Ids of the parent nodes open at first render (uncontrolled).

string[][]
onExpandedChange

Called with every open id whenever a node is expanded or collapsed.

(ids: string[]) => void—
selectionMode

How nodes can be selected. See TreeViewSelectionMode.

"none""single""multiple""single"
selected

Ids of the selected (or, with checkboxes, checked) nodes (controlled).

string[]—
defaultSelected

Ids selected at first render (uncontrolled).

string[][]
onSelectedChange

Called with every selected id whenever the selection changes. With checkboxes, fully checked parents are included and partly checked ones are not.

(ids: string[]) => void—
checkboxes

With selectionMode="multiple", shows a checkbox on every node and uses aria-checked instead of aria-selected. Checking a parent checks all its (non-disabled) descendants; a partly checked parent is "mixed". Ignored in other modes.

booleanfalse
onAction

Called when a node is activated: Enter, or a click in none and single modes. Use it to open a file or navigate. Without it, activating a parent toggles it open. Never called for disabled nodes.

(id: string, node: TreeNode) => void—
loadChildren

Loads the children of a node marked hasChildren the first time it's expanded. A loading row (with aria-busy on the group) shows meanwhile; a rejection shows an error row (role="alert"). Collapse and expand the node to try again.

(node: TreeNode) => Promise<TreeNode[]>—
renderLabel

Custom label content. Receives the node and its state. Keep it non-interactive: the whole row is one control.

(node: TreeNode, state: TreeNodeState) => ReactNode—
size

Row height, text size, and indentation.

"sm""md""lg""md"
loadingLabel

Text of the loading row and its announcement.

string"Loading…"
errorLabel

Text of the error row when loadChildren fails.

string"Couldn't load items. Collapse and expand to try again."
aria-labelstring—
aria-labelledbystring—

Also accepts standard HTML attributes, plus className, style and ref.

See what changed in each version in the Changelog.

Accessibility report

TreeView targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.

axe-core audit (live)

Running accessibility audit

Checking the examples above…

Lighthouse audit

Light mode

Score 100

35 passed · 1 failed · 29 not applicable · 10 to check by hand

  • Elements with visible text labels do not have matching accessible names.

    Visible text labels that do not match the accessible name can result in a confusing experience for screen reader users. 5 elements.

    div._preview_d5du8_33 > div._root_1737j_15 > ul._root_lahq7_13 > li._item_lahq7_117div._preview_d5du8_33 > div > ul._root_lahq7_13 > li._item_lahq7_117ul._root_lahq7_13 > li._item_lahq7_117 > ul._group_lahq7_151 > li._item_lahq7_117div._preview_d5du8_33 > div > ul._root_lahq7_13 > li._item_lahq7_117div._root_sa02l_2 > div > ul._root_lahq7_13 > li._item_lahq7_117

Dark mode

Score 100

35 passed · 1 failed · 29 not applicable · 10 to check by hand

  • Elements with visible text labels do not have matching accessible names.

    Visible text labels that do not match the accessible name can result in a confusing experience for screen reader users. 5 elements.

    div._preview_d5du8_33 > div._root_1737j_15 > ul._root_lahq7_13 > li._item_lahq7_117div._preview_d5du8_33 > div > ul._root_lahq7_13 > li._item_lahq7_117ul._root_lahq7_13 > li._item_lahq7_117 > ul._group_lahq7_151 > li._item_lahq7_117div._preview_d5du8_33 > div > ul._root_lahq7_13 > li._item_lahq7_117div._root_sa02l_2 > div > ul._root_lahq7_13 > li._item_lahq7_117

Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.

Built-in behavior

Keyboard

Keyboard
KeyAction
Arrow DownArrow UpMoves to the next or previous visible item.
Arrow RightOpens a closed parent, or moves to its first child (mirrored right to left).
Arrow LeftCloses an open parent, or moves to the parent (mirrored right to left).
HomeEndMoves to the first or last visible item.
EnterActivates the item (onAction), or toggles a parent.
SpaceSelects the item (toggles it in multiple selection).
*Opens every sibling parent at this level.
TypingMoves to the next item that starts with the typed characters.
Shift+Arrow DownShift+Arrow UpMultiple selection: extends the selection.
Ctrl+AMultiple selection: selects all.

One tab stop: Tab lands on the selected item (or the first) and leaves the tree.

Roles and states

Roles and states
ElementRoleStates and properties
<ul>treearia-label, aria-multiselectable
Itemtreeitemaria-expanded (parents), aria-selected or aria-checked, aria-level, aria-posinset, aria-setsize
Childrengroup—

Manual checks

Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.

Manual accessibility checks
CheckWhat to testWCAG 2.2
KeyboardEvery action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck.2.1.1 (A), 2.1.2 (A)
FocusFocus moves in a logical order, is always visible, and isn't hidden behind sticky headers.2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA)
Screen readersNames, roles and states are announced correctly, and status changes are announced without moving focus.1.3.1 (A), 4.1.2 (A), 4.1.3 (AA)
ColorMeaning never depends on color alone; your own colors meet contrast in both modes.1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA)
Zoom and reflowAt 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed.1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA)
Pointer targetsClick and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap.2.5.8 (AA), 2.5.5 (AAA)
MotionAnimations respect the reduced-motion setting.2.3.3 (AAA)