Tree API
View componentThe full prop reference for the Tree component. A hierarchical list, like a file explorer.
Import
import { Tree } from '@structyl/styled';Props
Tree.Root
Root component for the tree; manages expanded, selected, and focused states. Extends ul element.
| Prop | Type | Default |
|---|---|---|
| asChild# | booleanReplace element with first child and merge props | — |
| defaultExpanded# | string[]Initial expanded item IDs (uncontrolled) | [] |
| expanded# | string[]Controlled expanded item IDs | — |
| onExpandedChange# | (expanded: string[]) => voidCallback when expanded items change | — |
| defaultSelected# | stringInitial selected item ID (uncontrolled) | — |
| selected# | stringControlled selected item ID | — |
| onSelectedChange# | (id: string | undefined) => voidCallback when selected item changes | — |
| className# | stringCSS class names (styled adds 'text-sm' default) | — |
| ref# | React.Ref<HTMLUListElement>Forward ref to underlying ul element | — |
Tree.Item
Container for a tree item. Extends li element. Must be a direct child of Root or Group.
| Prop | Type | Default |
|---|---|---|
| id# | stringUnique identifier for the tree item (required) | — |
| asChild# | booleanReplace element with first child and merge props | — |
| hasChildren# | booleanWhether this item has child items (shows expand chevron) | false |
| level# | numberNesting level for accessibility (aria-level) | 1 |
| className# | stringCSS class names | — |
| ref# | React.Ref<HTMLLIElement>Forward ref to underlying li element | — |
Tree.Trigger
Clickable trigger for item expansion and selection. Extends div element.
| Prop | Type | Default |
|---|---|---|
| hasChildren# | booleanWhen false, hides the expand chevron icon (styled only) | — |
| className# | stringCSS class names (styled adds default styles for layout, hover, focus ring) | — |
| onClick# | (event: React.MouseEvent<HTMLDivElement>) => voidNative click handler (composed with selection/expansion logic) | — |
| onFocus# | (event: React.FocusEvent<HTMLDivElement>) => voidNative focus handler (composed with focus tracking) | — |
| onKeyDown# | (event: React.KeyboardEvent<HTMLDivElement>) => voidNative keydown handler (composed with keyboard navigation: Arrow Right/Left for expand/collapse, Enter/Space for select) | — |
| ref# | React.Ref<HTMLDivElement>Forward ref to underlying div element | — |
Tree.Group
Container for child tree items. Only renders when parent item is expanded. Extends ul element.
| Prop | Type | Default |
|---|---|---|
| className# | stringCSS class names (styled adds left border and left padding) | — |
| ref# | React.Ref<HTMLUListElement>Forward ref to underlying ul element | — |
Source code
If you didn't find what you need here, read the component implementation .