- Docs
- Components
- Data display
Tree view
A hierarchy to open, close and choose from: organisation units, nested groups, permissions.
- Import
- @qeetrix/react/experimental
- Status
- ExperimentalSince 0.0.6
- Renders
<ul role="tree">Server-rendered- Tested
- WCAG 2.2 AAaxe on every pull request
01
Import
// Experimental: from the package's experimental entry, until it's stable.
import { TreeView, TreeNode } from "@qeetrix/react/experimental";02
Props
And every native attribute of the element it renders.
| Prop | Type | Default | What it does |
|---|---|---|---|
label | string | required | Names the tree: "Organisation units". |
items | TreeNode[] | required | Each node: id, label, and icon, meta, children, disabled. |
expanded · defaultExpanded · onExpandedChange | string[] | [] | The open nodes' ids. |
selected · defaultSelected · onSelectedChange | string | null | null | The selected node's id, by Enter, Space or a click. Not with checkable. |
checkable | boolean | false | A checkbox per node; a parent is mixed while some of its nodes are on. |
checked · defaultChecked · onCheckedChange | string[] | [] | The checked nodes without children. |
TreeNode: disabled | boolean | false | Can't be selected, ticked, opened or closed; the keys and a parent's tick skip it, and so do the nodes under it. |
03
Parts
Each part carries a data-slot, for tests and placement.
| data-slot | Element | What it is |
|---|---|---|
tree-view | <ul role="tree"> | aria-label. |
tree-item | <li role="treeitem"> | aria-level, aria-setsize, aria-posinset, aria-expanded, aria-selected or aria-checked. |
tree-row | <div> | The row's guides, toggle, check, icon, label and meta. |
tree-group | <ul role="group"> | An open node's children. |
tree-check | <span> | With checkable: the checkbox, aria-hidden. |
04
Loaded as it opens
Fetch a node's children when it opens, and keep expanded in state while they come.
const [expanded, setExpanded] = useState<string[]>([]);
const items = useUnitTree(expanded);
<TreeView label="Organisation units" items={items} expanded={expanded} onExpandedChange={setExpanded} />