Component reference
TreeView
Browse an application-controlled file hierarchy.
Preview
Live previewOptional six-digit hex. Clear to restore the preset. Check contrast with your brand color.
Changes apply to this preview only.
- src
- components
- button.tsx
- card.tsx
- tabs.tsx
- App.tsx
- styles.css
- tests
- README.md
- package.json
Width adapts to the available space
"use client";
import { useState } from "react";
import { Badge, TreeView, type PimoluTreeItem } from "@pimolu/react";
const files: PimoluTreeItem[] = [
{
id: "src",
label: "src",
children: [
{
id: "components",
label: "components",
children: [
{ id: "button", label: "button.tsx" },
{ id: "card", label: "card.tsx" },
{ id: "tabs", label: "tabs.tsx" },
],
},
{ id: "app", label: "App.tsx" },
{ id: "styles", label: "styles.css" },
],
},
{
id: "tests",
label: "tests",
children: [
{ id: "button-test", label: "button.test.tsx" },
{ id: "card-test", label: "card.test.tsx" },
],
},
{ id: "readme", label: "README.md" },
{ id: "package", label: "package.json" },
];
function ControlledTree() {
const [selected, setSelected] = useState("tabs");
const [expanded, setExpanded] = useState<string[]>([
"src",
"components",
]);
return (
<div className="grid gap-5 min-w-0">
<div className="flex flex-wrap items-center gap-3 min-w-0">
<Badge variant="primary">
{selected ?? "none"}
</Badge>
<span className="text-sm text-muted leading-relaxed">
expanded: {expanded.join(", ") || "none"}
</span>
</div>
<TreeView
items={files}
aria-label="Controlled file tree"
selectedId={selected}
onSelectedChange={(id) => setSelected(id ?? "")}
expandedIds={expanded}
onExpandedChange={setExpanded}
/>
</div>
);
}
export function DemoExample() {
return (<ControlledTree />);
}More examples
Different configurations and compositions using the real Pimolu API. Each preview runs independently and follows the site appearance.
Controlled document selection
Application state follows a selected document; expansion stays independent.
File tree
Click a folder to select and toggle it; disabled nodes are skipped by the keyboard.
Disabled branch
A disabled node keeps its label but cannot be selected or focused.
Usage
Separate expansion from selection and use stable ids when nodes are updated.
API reference
Generated from the public TypeScript declarations. Native HTML attributes are inherited where the component extends them; this reference includes Pimolu props and selected common native attributes.
PimoluTreeItem
Type source| Name | Type | Default | Description |
|---|---|---|---|
idRequired | string | — | Public Pimolu prop; see the source declaration for details. |
labelRequired | ReactNode | — | Visible label associated with the control. |
children | readonly PimoluTreeItem[] | undefined | — | Public Pimolu prop; see the source declaration for details. |
disabled | boolean | undefined | — | Public Pimolu prop; see the source declaration for details. |
idRequiredstringNo default extracted.
Public Pimolu prop; see the source declaration for details.
labelRequiredReactNodeNo default extracted.
Visible label associated with the control.
childrenreadonly PimoluTreeItem[] | undefinedNo default extracted.
Public Pimolu prop; see the source declaration for details.
disabledboolean | undefinedNo default extracted.
Public Pimolu prop; see the source declaration for details.
PimoluTreeViewProps
Type source| Name | Type | Default | Description |
|---|---|---|---|
itemsRequired | readonly PimoluTreeItem[] | — | Public Pimolu prop; see the source declaration for details. |
expandedIds | readonly string[] | undefined | — | Controlled expanded ids. |
defaultExpandedIds | readonly string[] | undefined | [] | Initial expanded ids when uncontrolled. |
onExpandedChange | ((ids: string[]) => void) | undefined | — | Public Pimolu prop; see the source declaration for details. |
selectedId | string | undefined | — | Controlled selected id. |
defaultSelectedId | string | undefined | — | Initial selected id when uncontrolled. |
onSelectedChange | ((id: string | undefined) => void) | undefined | — | Public Pimolu prop; see the source declaration for details. |
aria-labelRequired | string | — | Accessible name of the tree. |
className | string | undefined | — | Public Pimolu prop; see the source declaration for details. |
itemsRequiredreadonly PimoluTreeItem[]No default extracted.
Public Pimolu prop; see the source declaration for details.
expandedIdsreadonly string[] | undefinedNo default extracted.
Controlled expanded ids.
defaultExpandedIdsreadonly string[] | undefinedDefault: []
Initial expanded ids when uncontrolled.
onExpandedChange((ids: string[]) => void) | undefinedNo default extracted.
Public Pimolu prop; see the source declaration for details.
selectedIdstring | undefinedNo default extracted.
Controlled selected id.
defaultSelectedIdstring | undefinedNo default extracted.
Initial selected id when uncontrolled.
onSelectedChange((id: string | undefined) => void) | undefinedNo default extracted.
Public Pimolu prop; see the source declaration for details.
aria-labelRequiredstringNo default extracted.
Accessible name of the tree.
classNamestring | undefinedNo default extracted.
Public Pimolu prop; see the source declaration for details.
Accessibility
- Verify the tree's arrow-key model, focus position and disabled branches.