Searching Puzzle Pieces

Type to search Puzzle Pieces.

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
  • 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
  • index.js
  • package.json
  • README.md

Expanded: src

Disabled nodes

  • 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.

KeyAction
Down / UpMove focus to the next / previous visible row.
RightExpand a collapsed parent; on an expanded parent, focus its first child.
LeftCollapse an expanded parent; otherwise focus the parent row.
Home / EndFocus the first / last visible row.
Enter / SpaceSelect 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 a role="treeitem".
  • Each item carries aria-level, aria-posinset, and aria-setsize, so the flattened rows are announced with their true depth and position.
  • Parents expose aria-expanded; the selected row is aria-selected, and disabled rows are aria-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).