Skip to content
Stylhero 0.8.0
Components

Core

Layout and type

Inputs

Overlays

Navigation

Data display

Charts

Transitions and utilities

Page pieces (landing pages, portfolios, docs)

Icons

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

PropTypeDefaultDescription
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

KeyDoes
ArrowDown / ArrowUpNext / previous visible item
ArrowRightExpands an item, or moves to its first child
ArrowLeftCollapses an item, or moves to its parent
Home / EndFirst / last visible item
EnterSelects the item and expands or collapses it
SpaceSelects the item

Accessibility

  • Follows the ARIA tree pattern (tree, treeitem with aria-expanded and aria-selected). Only one item is in the Tab order.

Generated from src/components/TreeView.tsx. Something wrong or missing? Open an issue.