Skip to content
Redpanda UI
Esc
↑↓navigate↵open⌘Jpreview
Edit on GitHub

Tree

Browse hierarchical data with keyboard navigation, selection, and checkboxes.

Powered by

Installation

bash
npx shadcn@latest add @redpanda/tree
bash
pnpm dlx shadcn@latest add @redpanda/tree
bash
yarn dlx shadcn@latest add @redpanda/tree
bash
bunx shadcn@latest add @redpanda/tree
bash
nubx shadcn@latest add @redpanda/tree
bash
aube dlx shadcn@latest add @redpanda/tree

Usage

Use paths for slash-separated file names or items for structured data. Item values must be unique across the tree.

tsx
import { Tree } from '@/components/redpanda-ui/components/tree';
<Tree  aria-label="Project files"  defaultExpanded={['src']}  paths={['src/app.tsx', 'src/components/button.tsx', 'package.json']}/>;

Custom rows

Compose the styled parts to add icons, links, or custom content. Use TreeItemLabel for each row’s accessible name and TreeGroup for its children.

tsx
import { Tree, TreeGroup, TreeItem, TreeItemIndicator, TreeItemLabel } from '@/components/redpanda-ui/components/tree';
<Tree aria-label="Project files">  <TreeItem value="src">    <TreeItemLabel>      <TreeItemIndicator />      Source    </TreeItemLabel>    <TreeGroup>      <TreeItem value="src/app.tsx">        <TreeItemLabel>app.tsx</TreeItemLabel>      </TreeItem>    </TreeGroup>  </TreeItem></Tree>;

Pass branch explicitly when a render function or another component hides the group from the item’s direct JSX children. Slots retain UI SDK’s render, state-based className, and ref support.

Controlled selection and expansion

Selection is single by default. Use mode="multiple" with an array value, or mode="none" to disable selection. Keep expanded separate from value.

Checkboxes

Checking and selection are independent. Add checkable to data-driven trees, or place TreeItemCheckbox inside each composed TreeItemLabel. The default leaf strategy derives mixed parent states from checked descendants.

Keyboard and accessibility

Give each tree an aria-label or aria-labelledby. Tab enters the tree at one item; arrow keys move between visible items. Right expands a branch or enters it, Left collapses it or moves to its parent, and Home/End move to the first/last visible item. Type to find a visible label. Enter selects or activates an item; Space checks it when checkable, otherwise selects it.

UI SDK owns tree roles, levels, selection, mixed checkbox states, disabled states, and roving focus. Disabled items remain focusable by default; use focusableWhenDisabled={false} to skip them. Test with the assistive technologies used by your application.

Large or asynchronous trees

Import createTreeController, treeFromPaths, and visibleTreeRows from @ui-sdk/core/tree. For asynchronous branches, use loadChildren and update your items or composed children before its promise resolves. Mark an empty branch with children: [] in data, or branch in composed JSX.

Virtualization is consumer-owned, not bundled with this component. Supply the complete items model, render a window of visibleTreeRows(items, expanded), and use onHighlight to scroll the active row into view. Follow the UI SDK virtualization example for the full wiring and level-based indentation.

This is a general-purpose tree, not a JSON viewer or editor. Use JSON Viewer for JSON values.

Recent changes

  • patchv1.2.0Pin shipped dependency floors to the version we develop against. Registry items now declare ranges like `^5.1.9` (the actual installed version) instead of collapsing to `^5.0.0`, so consumers start on the known-tested baseline while caret semantics still allow any compatible release within the same major.#133
  • minorv1.1.0Theme docs refresh, readability pass on semantic foregrounds, and consumer-facing Base UI regression fixes.#121
  • minorv1.0.0Post-Base-UI polish. Public API unchanged.#116
  • majorv1.0.0Migrate every Radix-based primitive to `@base-ui/react@^1.4.0` (Base UI).#114
  • minorv0.3.0Add theme-provider component to the registry with documentation and tests. Includes playground type improvements (export RegistryItem, remove as-const boilerplate) and docs site dark mode border color fix.#109
See full history →

Last updated on

Was this page helpful?