Tree
Browse hierarchical data with keyboard navigation, selection, and checkboxes.
Powered by
Installation
npx shadcn@latest add @redpanda/treepnpm dlx shadcn@latest add @redpanda/treeyarn dlx shadcn@latest add @redpanda/treebunx shadcn@latest add @redpanda/treenubx shadcn@latest add @redpanda/treeaube dlx shadcn@latest add @redpanda/treeUsage
Use paths for slash-separated file names or items for structured data. Item values must be unique across the tree.
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.
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.