Tree <pm-tree>
Tree view (file browsers, nested navigation).
Overview
Full keyboard support per the WAI-ARIA tree pattern: ↑/↓ move, → expands or enters, ← collapses or goes to the parent, Home/End, Enter/Space select, type-ahead. selection="checkbox": tri-state checkboxes that cascade to children and parents (Space toggles; values lists checked leaves). filter shows matching items and their ancestors, highlighted. lazy items load children on first expand (pm-load).
Children from an API: set src (src="/api/folders/{value}/children", {value} is the expanded item's value) or the loader property (async (item, { signal }) => items); the tree then builds the child items itself from label-key, value-key, lazy-key (has children to load), icon-key and children-key (nested items), or from mapItem. Failures collapse the item again and fire pm-load-error.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
label | string | — | Accessible name (and visible label where the component shows one). |
value | string | — | Value of the selected item. |
selection | 'single' | 'checkbox' | — | single (default) or checkbox (tri-state, cascading). |
filter | string | — | Show only items whose label contains this text (plus their ancestors). |
empty-textprop: emptyText | string | — | Shown when the filter matches nothing. |
src | string | — | URL for an item's children; {value} is replaced with the expanded item's value. Response: JSON. |
children-pathprop: childrenPath | string | — | Where the list is in the response (dotted path; empty = the response itself). |
label-keyprop: labelKey | string | — | Item field for the label (default label, then name, then title). |
value-keyprop: valueKey | string | — | Item field for the value (default value, then id). |
lazy-keyprop: lazyKey | string | — | Item field that says it has children to load on expand (default lazy, then hasChildren). |
icon-keyprop: iconKey | string | — | Item field with a registered icon name (default icon). |
children-keyprop: childrenKey | string | — | Item field with nested child items (default children). |
Also accepts the contextual attributes tone, surface, radius, density, motion, elevation. They are inherited from ancestors' data-* attributes.
Events
| Event | React / Svelte prop | Description |
|---|---|---|
pm-select | onPmSelect | An item was selected. |
pm-check | onPmCheck | Checkboxes changed. |
pm-load | onPmLoad | A lazy item was expanded for the first time; append its children (done for you with src / loader). |
pm-load-error | onPmLoadError | Loading children failed. |
Slots
| Slot | Description |
|---|---|
(default) | pm-tree-item elements (nest them for children). |
Methods
setChecked(), appendItems(), visibleItems(), select()
<pm-tree-item>
Tree node. Nest pm-tree-items inside to make a branch.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
icon | string | — | Registered icon name (see registerIcons); an icon slot overrides it. |
label | string | — | Accessible name (and visible label where the component shows one). |
value | string | — | Current value. |
expanded | boolean | false | Whether its children are shown. |
selected | boolean | false | Whether this item is selected. |
disabled | boolean | false | Not interactive (and not submitted, for form controls). |
checked | boolean | false | Checkbox state (tree selection="checkbox"). |
indeterminate | boolean | false | Some (not all) children are checked. Set by the tree. |
lazy | boolean | false | Has children that load on first expand (pm-load on the tree). |
loading | boolean | false | Children are loading (cleared when they arrive). |
Also accepts the contextual attributes tone, surface, radius, density, motion, elevation. They are inherited from ancestors' data-* attributes.
Events
| Event | React / Svelte prop | Description |
|---|---|---|
pm-toggle | onPmToggle | Branch expanded or collapsed. |
Slots
| Slot | Description |
|---|---|
(default) | Child pm-tree-item elements. |
icon | Icon before the label. |
end | Trailing content (count, badge, actions). |
Methods
childItems(), toggle()