TreeView
A hierarchical collection with expansion, selection, and keyboard navigation.
TreeViewView sourceExample
The preview is interactive. The code below it is the docs demo source; demo-only layout classes can be omitted in application code.
- source
- ui
- Button.tsx
- Input.tsx
- Legacy.tsx
- App.tsx
- public
- README.md
import { TreeView } from "innate-ui";
export function TreeViewDemo() {
return (
<TreeView ariaLabel="Project files" defaultExpanded={["source", "ui"]}>
<TreeView.Item value="source" label="source">
<TreeView.Item value="ui" label="ui">
<TreeView.Item value="button" label="Button.tsx" />
<TreeView.Item value="input" label="Input.tsx" />
<TreeView.Item value="legacy" label="Legacy.tsx" disabled />
</TreeView.Item>
<TreeView.Item value="app" label="App.tsx" />
</TreeView.Item>
<TreeView.Item value="public" label="public">
<TreeView.Item value="favicon" label="favicon.svg" />
</TreeView.Item>
<TreeView.Item value="readme" label="README.md" />
</TreeView>
);
}API reference
This table is generated from Innate UI's exported TypeScript declarations and JSDoc. Native element attributes inherited by a prop type are not repeated here.
TreeViewProps
| Prop | Type | Default |
|---|---|---|
childrenrequiredTop-level `TreeView.Item` children. | JSX.Children | — |
ariaLabelrequiredAccessible label for the tree. | JSX.ValueOrCell<string> | — |
expandedExternally owned reactive set of expanded item values. | SourceCell<ReadonlySet<TreeViewValue>> | — |
defaultExpandedInitial expanded values used when `expanded` is not supplied. | Iterable<TreeViewValue> | — |
onExpandedChangeCalled whenever the expanded set changes. | (expanded: ReadonlySet<TreeViewValue>) => void | — |
onClickClick handler called before built-in tree click handling. | EventHandlerProp<HTMLUListElement, MouseEvent> | — |
onFocusFocus handler called before built-in focus management. | EventHandlerProp<HTMLUListElement, FocusEvent> | — |
onKeyDownKey-down handler called before built-in tree keyboard navigation. | EventHandlerProp<HTMLUListElement, KeyboardEvent> | — |
TreeViewItemProps
| Prop | Type | Default |
|---|---|---|
valuerequiredUnique value identifying this item in the tree. | TreeViewValue | — |
labelrequiredVisible item label. | JSX.Children | — |
childrenNested `TreeView.Item` children. | JSX.Children | — |
disabledWhether the item is disabled. | JSX.ValueOrCell<boolean> | false |
textValueText used for typeahead when it cannot be inferred from `label`. | JSX.ValueOrCell<string> | — |
hasChildrenMarks an item as expandable even when its children are loaded asynchronously. | JSX.ValueOrCell<boolean> | false |
loadingWhether the item's children are currently loading. | JSX.ValueOrCell<boolean> | false |