Tree
A config-first WAI-ARIA tree view. One nodes array of nested objects renders an expand/collapse file-explorer tree with roving-tabindex keyboard navigation, controlled selection, and an optional-controlled expanded set.
- src
- components
- Button.pzl
- Tree.pzl
- index.js
- public
- package.json
- README.md
Selected: Tree.pzl
Installation
Copy the piece into your app — it compiles with your build and the code is yours:
puzzle add piece tree
Selection is controlled (the parent owns value); expansion is optional-controlled — omit expanded and the Tree owns it internally.
Usage
import Tree from '@/components/ui/Tree.pzl';
<Tree nodes={ nodes } value={ selected } expanded={ expanded } label="Project files" @select={ onSelect } @toggle={ onToggle } />Controlled expansion
- src
- components
- index.js
- public
- package.json
- README.md
Expanded: src
Disabled nodes
- Engineering
- Design (archived)
- Sol Byrne
A disabled node is aria-disabled and cannot be selected or toggled, but stays reachable by keyboard.
Keyboard
The tree is a single Tab stop (roving tabindex): exactly one visible row is tabbable — the last-focused row (else the selected row, else the first enabled root). Focus then moves with the arrow keys over the visible rows.
| Key | Action |
|---|---|
| Down / Up | Move focus to the next / previous visible row. |
| Right | Expand a collapsed parent; on an expanded parent, focus its first child. |
| Left | Collapse an expanded parent; otherwise focus the parent row. |
| Home / End | Focus the first / last visible row. |
| Enter / Space | Select the row (a parent also expands or collapses). |
Accessibility
- The root is a
role="tree"list with an accessible label prop (default Tree); every row is arole="treeitem". - Each item carries
aria-level,aria-posinset, andaria-setsize, so the flattened rows are announced with their true depth and position. - Parents expose
aria-expanded; the selected row isaria-selected, and disabled rows arearia-disabled. - Roving tabindex keeps the tree one Tab stop; arrow keys move focus and expand/collapse. Every row shows a visible focus ring (unconditional outline color, revealed on
:focus-visible).