Fine-tune light, shadows, borders, neumorphic
Light and shadows
Borders
Neumorphic
Data

Tree <pm-tree>

Tree view (file browsers, nested navigation).

Full screen
2

Props

<script type="module"> import '@prismora/css'; import '@prismora/elements/badge'; import '@prismora/elements/icon'; import '@prismora/elements/tree'; import { registerIcons } from '@prismora/elements/icon'; import { code, file, fileText, folder } from '@prismora/icons'; registerIcons([code, file, fileText, folder]); </script> <pm-tree label="Project files"> <pm-tree-item label="src" expanded> <pm-icon slot="icon" name="folder"></pm-icon> <pm-tree-item label="components"> <pm-icon slot="icon" name="folder"></pm-icon> <pm-badge slot="end" tone="neutral">2</pm-badge> <pm-tree-item label="Button.ts"> <pm-icon slot="icon" name="code"></pm-icon> </pm-tree-item> <pm-tree-item label="Card.ts"> <pm-icon slot="icon" name="code"></pm-icon> </pm-tree-item> </pm-tree-item> <pm-tree-item label="index.ts"> <pm-icon slot="icon" name="code"></pm-icon> </pm-tree-item> </pm-tree-item> <pm-tree-item label="package.json"> <pm-icon slot="icon" name="file"></pm-icon> </pm-tree-item> <pm-tree-item label="README.md"> <pm-icon slot="icon" name="file-text"></pm-icon> </pm-tree-item> </pm-tree> <pm-tree label="Permissions" selection="checkbox"> <pm-tree-item label="Billing" expanded> <pm-tree-item label="View invoices" value="billing.view" checked></pm-tree-item> <pm-tree-item label="Pay invoices" value="billing.pay"></pm-tree-item> </pm-tree-item> <pm-tree-item label="Members" expanded> <pm-tree-item label="Invite" value="members.invite"></pm-tree-item> <pm-tree-item label="Remove" value="members.remove"></pm-tree-item> </pm-tree-item> </pm-tree>

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

AttributeTypeDefaultDescription
labelstring—Accessible name (and visible label where the component shows one).
valuestring—Value of the selected item.
selection'single' | 'checkbox'—single (default) or checkbox (tri-state, cascading).
filterstring—Show only items whose label contains this text (plus their ancestors).
empty-text
prop: emptyText
string—Shown when the filter matches nothing.
srcstring—URL for an item's children; {value} is replaced with the expanded item's value. Response: JSON.
children-path
prop: childrenPath
string—Where the list is in the response (dotted path; empty = the response itself).
label-key
prop: labelKey
string—Item field for the label (default label, then name, then title).
value-key
prop: valueKey
string—Item field for the value (default value, then id).
lazy-key
prop: lazyKey
string—Item field that says it has children to load on expand (default lazy, then hasChildren).
icon-key
prop: iconKey
string—Item field with a registered icon name (default icon).
children-key
prop: 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

EventReact / Svelte propDescription
pm-selectonPmSelectAn item was selected.
pm-checkonPmCheckCheckboxes changed.
pm-loadonPmLoadA lazy item was expanded for the first time; append its children (done for you with src / loader).
pm-load-erroronPmLoadErrorLoading children failed.

Slots

SlotDescription
(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

AttributeTypeDefaultDescription
iconstring—Registered icon name (see registerIcons); an icon slot overrides it.
labelstring—Accessible name (and visible label where the component shows one).
valuestring—Current value.
expandedbooleanfalseWhether its children are shown.
selectedbooleanfalseWhether this item is selected.
disabledbooleanfalseNot interactive (and not submitted, for form controls).
checkedbooleanfalseCheckbox state (tree selection="checkbox").
indeterminatebooleanfalseSome (not all) children are checked. Set by the tree.
lazybooleanfalseHas children that load on first expand (pm-load on the tree).
loadingbooleanfalseChildren 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

EventReact / Svelte propDescription
pm-toggleonPmToggleBranch expanded or collapsed.

Slots

SlotDescription
(default)Child pm-tree-item elements.
iconIcon before the label.
endTrailing content (count, badge, actions).

Methods

childItems(), toggle()