Single-select hierarchical tree derived from flat ordered item data.
Install @wyrd-company/react or the Flutter package and use it directly —
your DESIGN.md does the styling.
catalog/contracts/tree-view.ymlsource of truth · verbatim
$schema: https://thewyrdingway.dev/schemas/component-contract.schema.ymlcontractVersion: 0.1.0identity:name: TreeViewtag: wyrd-tree-viewpackage: wyrd.component.tree-viewtitle: TreeViewsummary: Single-select hierarchical tree derived from flat ordered item data.relationships:related-to: - quality-parity-and-gatesclassification:category: navigationcomposition: collectioninteractive: truetarget-strategy:react: requiredflutter: requiredsurface:properties: - name: labeltype:kind: stringrequired: trueserializable: truesummary: Accessible name for the tree. - name: itemstype:kind: arrayitem:kind: objectfields:label:kind: stringvalue:kind: stringhref:kind: stringparent-value:kind: stringdisabled:kind: booleanrequired: falsedefault: []serializable: truesummary: Flat ordered tree item data. Items without parent-value are roots; parent records must appear before child records. - name: expanded-valuestype:kind: arrayitem:kind: stringrequired: falsecontrolled: trueserializable: truesummary: Controlled expanded parent values. - name: default-expanded-valuestype:kind: arrayitem:kind: stringrequired: falsedefault: []serializable: truesummary: Initial uncontrolled expanded parent values. - name: selected-valuetype:kind: stringrequired: falsecontrolled: trueserializable: truesummary: Controlled selected item value. - name: default-selected-valuetype:kind: stringrequired: falseserializable: truesummary: Initial uncontrolled selected item value.slots: []events: - name: expanded-changepayload:expanded-values:kind: arrayitem:kind: stringbubbles: truecomposed: truecancelable: falsesummary: Emitted with the full new expanded value set after expansion state changes. - name: selection-changepayload:value:kind: stringbubbles: truecomposed: truecancelable: falsesummary: Emitted when the user selects an enabled tree item. - name: navigation-requestpayload:value:kind: stringhref:kind: stringbubbles: truecomposed: truecancelable: truesummary: Emitted when the user activates a tree item with a navigation destination.states: - name: defaultsource: platformsummary: Tree collection is visible. - name: expandedsource: propertysummary: One or more parent items are expanded. - name: selectedsource: propertysummary: One tree item is selected. - name: focus-visiblesource: platformsummary: Keyboard-visible focus state on a tree item. - name: disabledsource: propertysummary: Disabled item state.parts: - name: rootsummary: Tree root. - name: itemsummary: Repeated tree item row. - name: chevronsummary: Parent item expansion affordance. - name: labelsummary: Tree item label text. - name: groupsummary: Child item group.tokens:item:foreground: color.on-surfacebackground: color.surfaceselected-background: color.primaryselected-foreground: color.on-primaryhover-background: color.secondaryindent: spacing.lgchevron:color: color.on-surfacemessages: []obligations:accessibility:role: treename: Label property provides the required accessible name.keyboard: - ArrowDown moves focus to the next visible enabled item. - ArrowUp moves focus to the previous visible enabled item. - ArrowRight expands a focused collapsed parent, or moves to its first visible child when already expanded. - ArrowLeft collapses a focused expanded parent, or moves focus to its parent. - Home and End move focus to the first and last visible enabled item. - Enter and Space select the focused enabled item.semantics: - Web projections use ul/li tree structure with role=tree, role=treeitem, group containers, aria-level, aria-setsize, aria-posinset, aria-selected, and aria-expanded only on parent items. - Disabled items render but are skipped by roving tabindex and cannot be selected. - Navigable web items expose native anchors so standard link actions remain available. - Selection does not auto-expand ancestors in v1. - Flutter exposes expanded and selected flags through Semantics and renders visible rows as an indented flattened list.behavior:model: collectioninteractions: - Hierarchy is derived at runtime from flat item data. - Source item order defines sibling order. - Parent records must appear before their children; dangling children are rendered as roots and reported with console.warn on web targets. - expanded-values ?? default-expanded-values determines the effective expanded set. - selected-value ?? default-selected-value determines the effective single selection. - Arrow-key focus movement uses only visible enabled items. - Expanding or collapsing does not change selection.hostEffects: - Dispatch expanded-change with the full expanded value set. - Dispatch selection-change with the selected item value. - Dispatch navigation-request when an item with href is activated; canceling it prevents native navigation.conditions: - rtl - reduced-motion - cvd-deuteranopia - density-compact - text-expansionsdui:status: serializableserializableProperties: - label - items - expanded-values - default-expanded-values - selected-value - default-selected-valueserializableSlots: []eventBindings: - expanded-change - selection-change - navigation-requestnotes: TreeView serializes a flat ordered item array. Hosts derive the hierarchy at runtime, preserve sibling order, and treat dangling parent references as root items.examples: - name: file-explorerstate: expandedproperties:label: Project filesdefault-expanded-values: - src - componentsdefault-selected-value: buttonitems: - label: srcvalue: src - label: componentsvalue: componentsparent-value: src - label: Button.tsxvalue: buttonparent-value: componentshref: /docs/components/button - label: Dialog.tsxvalue: dialogparent-value: components - label: package.jsonvalue: packageslots: {} - name: disabled-itemstate: disabledproperties:label: Project filesdefault-expanded-values: - srcitems: - label: srcvalue: src - label: generatedvalue: generatedparent-value: srcdisabled: true - label: index.tsvalue: indexparent-value: srcslots: {}
01
Examples
Generated from the contract's examples block.
Previews are the published @wyrd-company/react component, themed by the
brand's role tokens — flip the site's light/dark toggle and they follow.
Flat ordered tree item data. Items without parent-value are roots; parent records must appear before child records.
expanded-values
array
undefined
Controlled expanded parent values.
default-expanded-values
array
Initial uncontrolled expanded parent values.
selected-value
string
undefined
Controlled selected item value.
default-selected-value
string
undefined
Initial uncontrolled selected item value.
03
Slots & events
Event
Payload
Summary
expanded-change
expanded-values
Emitted with the full new expanded value set after expansion state changes.
selection-change
value
Emitted when the user selects an enabled tree item.
navigation-request
value, href
Emitted when the user activates a tree item with a navigation destination.
04
Tokens
The contract's token bindings. Open the shared contextual sidebar from any example;
primary swatches reflect the color you pick there. Error swatches show the active
preset's values; editing any knob switches to custom and resets error to TWW · Ink.
Binding
Token
item.foreground
color.on-surface
item.background
color.surface
item.selected-background
color.primary
item.selected-foreground
color.on-primary
item.hover-background
color.secondary
item.indent
spacing.lg
chevron.color
color.on-surface
05
States
State
Source
Summary
default
platform
Tree collection is visible.
expanded
property
One or more parent items are expanded.
selected
property
One tree item is selected.
focus-visible
platform
Keyboard-visible focus state on a tree item.
disabled
property
Disabled item state.
06
Accessibility
From the contract's accessibility obligations. Role tree; Label property provides the required accessible name.
ArrowDown moves focus to the next visible enabled item.
ArrowUp moves focus to the previous visible enabled item.
ArrowRight expands a focused collapsed parent, or moves to its first visible child when already expanded.
ArrowLeft collapses a focused expanded parent, or moves focus to its parent.
Home and End move focus to the first and last visible enabled item.
Enter and Space select the focused enabled item.
Web projections use ul/li tree structure with role=tree, role=treeitem, group containers, aria-level, aria-setsize, aria-posinset, aria-selected, and aria-expanded only on parent items.
Disabled items render but are skipped by roving tabindex and cannot be selected.
Navigable web items expose native anchors so standard link actions remain available.
Selection does not auto-expand ancestors in v1.
Flutter exposes expanded and selected flags through Semantics and renders visible rows as an indented flattened list.