---
title: Tree
description: Browse hierarchical data with keyboard navigation, selection, and checkboxes.
icon: folder-tree
mode: wide
sidebar:
  badge: New
search:
  keywords: [treeview, file explorer, hierarchy, folders]
related: [/collapsible, /json-viewer]
---

<PoweredBy packages={[{ name: 'UI SDK', url: 'https://ui-sdk.dev/docs/react/components/tree' }]} />

## Installation

```package-install
npx shadcn@latest add @redpanda/tree
```

:::warning[UI SDK beta]
Tree requires React 19 or later. The registry pins both `@ui-sdk/core` and `@ui-sdk/react` to `0.1.0-beta.5` because UI SDK is in beta. Review upstream changes before upgrading either package.
:::

<ComponentPreview name="tree-demo" description="Browse project files with expandable folders." />

## 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`.

<ComponentPreview
  name="tree-controlled-demo"
  description="Control multiple selection and expand or collapse every branch."
/>

### 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.

<ComponentPreview
  name="tree-checkboxes-demo"
  description="Choose resources to export, including mixed and unavailable states."
/>

## 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](https://ui-sdk.dev/docs/react/components/tree#virtualized) for the full wiring and level-based indentation.

This is a general-purpose tree, not a JSON viewer or editor. Use [JSON Viewer](/docs/json-viewer) for JSON values.
