Navigation & Menus
@hacline/ui/treeTree
Navigate hierarchical items that can expand and collapse.
Usage
Browse, collapse, or expand folders using arrow keys. The example builds the hierarchy from items and tracks selection and expansion via node values.
"use client";
import { Tree } from "@/components/ui/hacline/components/tree";
import type { TreeItemData } from "@/components/ui/hacline/components/tree";
const files: TreeItemData[] = [
{
children: [
{ label: "delivery-checklist.md", value: "delivery" },
{ label: "release-process.md", value: "release" },
],
label: "Project docs",
value: "docs",
},
{ label: "README.md", value: "readme" },
];
export const Example = () => (
<Tree
aria-label="Project files"
className="max-w-xs"
defaultExpanded={["docs"]}
defaultValue="delivery"
items={files}
/>
);Cascading Checkable Folders
Combine checkable with checkStrategy="leaf" to report checked leaf items in callbacks.
"use client";
import { useState } from "react";
import { Tree } from "@/components/ui/hacline/components/tree";
import type { TreeItemData } from "@/components/ui/hacline/components/tree";
const items: TreeItemData[] = [
{
children: [
{ label: "Review notes", value: "review" },
{ label: "Delivery checklist", value: "delivery" },
],
label: "Design docs",
value: "design",
},
{ label: "Test report", value: "test-report" },
];
export const Example = () => {
const [checked, setChecked] = useState<string[]>(["review"]);
return (
<div className="grid w-full max-w-xs gap-2">
<Tree
aria-label="Select files to export"
checkStrategy="leaf"
checkable
checked={checked}
defaultExpanded={["design"]}
items={items}
mode="none"
onCheckedChange={setChecked}
/>
<output className="text-hl-fg-muted text-xs">
{checked.length} {checked.length === 1 ? "item" : "items"} selected
</output>
</div>
);
};Parts
| Part | Description |
|---|---|
TreeGroup | A branch's children. Rendered while the branch is expanded or animating closed. |
TreeItem | An item. Put its text in a TreeItemLabel and its children in a TreeGroup, which makes it a branch. Set branch for one whose children load later. |
TreeItemCheckbox | The item's checkbox, with checkable. Screen readers hear the item's checked state instead. |
TreeItemIndicator | The arrow that expands and collapses a branch. Alt or Option expands everything in it. |
TreeItemLabel | The item's text, which names it. Render it as a link to make the item one. |
TreeItems | Renders data items. Used by data trees, and available for custom layouts. |
Props
Prop
Type
Pagination
Navigate paginated results while highlighting the active page.
DataTable
Hybrid data table built on TanStack Table v9 and TanStack Virtual v3. Supports zero-boilerplate and composable APIs, sorting, faceted filtering, pagination, row selection, expandable rows, logical column pinning, column resizing, and 10k+ row virtualization.