Components / Data display
TreeView
Nested, collapsible list: folders, categories, branches → stores (MUI X's Tree View). Full arrow-key support.
import { TreeView } from "@stylhero/ui";
Example
Code
import { TreeView } from "@stylhero/ui";
function TreeViewExample() {
return (
<TreeView label="Files" defaultExpanded={["src"]} items={[
{ id: "src", label: "src", children: [{ id: "index", label: "index.ts" }, { id: "button", label: "Button.tsx" }] },
{ id: "docs", label: "docs", children: [{ id: "readme", label: "README.md" }] },
{ id: "pkg", label: "package.json" },
]} />
);
}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
items required |
TreeItem[] |
- | |
defaultExpanded |
string[] |
[] |
|
defaultSelected |
string | null |
null |
|
expanded |
string[] |
- | Controlled expanded ids. |
label |
string |
- | Accessible name. |
onExpandedChange |
(ids: string[]) => void |
- | |
onSelect |
(id: string) => void |
- | |
selected |
string | null |
- |
Also takes every <ul> attribute (id, style, data-*, aria-*, event handlers…), passed to that element.
Types
type TreeItem = { id: string; label: ReactNode; icon?: ReactNode; children?: TreeItem[]; disabled?: boolean };
Keyboard
| Key | Does |
|---|---|
| ArrowDown / ArrowUp | Next / previous visible item |
| ArrowRight | Expands an item, or moves to its first child |
| ArrowLeft | Collapses an item, or moves to its parent |
| Home / End | First / last visible item |
| Enter | Selects the item and expands or collapses it |
| Space | Selects the item |
Accessibility
- Follows the ARIA tree pattern (
tree,treeitemwitharia-expandedandaria-selected). Only one item is in the Tab order.
Generated from src/components/TreeView.tsx. Something wrong or missing? Open an issue.