Skip to main content
  1. Docs
  2. Components
  3. 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

tree-view.tsx
// 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.

PropTypeDefaultWhat it does
labelstringrequiredNames the tree: "Organisation units".
itemsTreeNode[]requiredEach node: id, label, and icon, meta, children, disabled.
expanded · defaultExpanded · onExpandedChangestring[][]The open nodes' ids.
selected · defaultSelected · onSelectedChangestring | nullnullThe selected node's id, by Enter, Space or a click. Not with checkable.
checkablebooleanfalseA checkbox per node; a parent is mixed while some of its nodes are on.
checked · defaultChecked · onCheckedChangestring[][]The checked nodes without children.
TreeNode: disabledbooleanfalseCan'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-slotElementWhat 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.

units.tsx
const [expanded, setExpanded] = useState<string[]>([]);
const items = useUnitTree(expanded);

<TreeView label="Organisation units" items={items} expanded={expanded} onExpandedChange={setExpanded} />
Next — Tree viewAccessibility