SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

treeKeys

Adapts the WAI-ARIA tree keyboard pattern onto a Tree's rows.

tsx
import { treeKeys } from "@sdxc/ui/app";

Usage

Turns a Tree's row list into the ARIA tree keyboard surface for its rows: arrow keys move, expand, and collapse; typed text searches labels; and every selection delegates to model, mirroring back and firing TreeChangeEvent.

Signature

typescript
treeKeys(model: SelectionModel): MixinDescriptor<HTMLElement>

Parameters

ParameterTypeDefaultRequiredDescription
modelSelectionModel—YesBehavior class instance owning the tree's selected-key set.

Examples

tsx
let model = new SelectionModel({ mode: "multiple" });
<div role="tree" mix={[treeKeys(model)]}>
  <div role="treeitem" aria-level={1} aria-expanded="true" data-tree-item="docs">Docs</div>
  <div role="treeitem" aria-level={2} data-tree-item="docs/readme">README</div>
</div>

The events, constants and types its module publishes, each imported from @sdxc/ui/app too.

Event

TreeChangeEvent

Dispatched on a Tree's row list by treeKeys whenever the bound SelectionModel's selection changes or the roving cursor moves rows, so a consumer can react without reading the model or DOM focus directly.

typescript
new TreeChangeEvent(init: {
		selectedKeys: ReadonlySet<SelectionModel.Key>;
		activeKey: SelectionModel.Key | null;
	})
PropertyTypeDefaultRequiredDescription
selectedKeysreadonly ReadonlySet<SelectionModel.Key>—YesKeys the bound model currently reports as selected.
activeKeyreadonly SelectionModel.Key | null—YesKey of the row currently holding the roving keyboard cursor, or null when no row has focus.
Constant

TREE_ITEM_ATTRIBUTE

Attribute every Tree row exposes itself on; its value doubles as the SelectionModel.Key treeKeys toggles, ranges over, and mirrors aria-selected onto, while aria-level/aria-expanded derive each row's place.

typescript
const TREE_ITEM_ATTRIBUTE = "data-tree-item"
@sdxc/ui

Can’t find it? Contact us