Skip to content

<sp-tree> API

An inline, WAI-ARIA tree with checkbox/radio selection, lazy loading, and a built-in search box. Renders the store’s rows() as a flat, indented list — collapsed and filtered-out rows are not in the DOM.

import '@sp-treeview/element'; // registers the element
import { SpTree } from '@sp-treeview/element'; // the class, for typing

Object/function inputs (data, loadChildren, renderNode, store) are DOM properties — set them via JS/framework binding, not string attributes. Primitive inputs also have a reflected attribute.

PropertyAttributeTypeDefaultDescription
dataTreeNodeData[][]The tree data (data model).
selectionselection'none' | 'single' | 'multi''none'Selection mode.
cascadecascadebooleantrueParent↔child propagation (multi).
loadOnceload-oncebooleantrueCache lazily-loaded children.
loadChildren(node) => Promise<TreeNodeData[]>Lazy loader for hasChildren nodes.
searchablesearchablebooleanfalseRender the built-in search box.
showAllNodeshow-all-nodebooleanfalseRender a top “All” row wired to setAllChecked.
renderNode(node, ctx) => TemplateResultCustom row content (Lit template); ctx is { row, store }.
storeTreeStoreUse an existing store; data/selection/cascade/loadOnce/loadChildren are then ignored.

All events are composed, bubbling CustomEvents.

EventdetailFires
sp-changemulti: { checked: TreeNodeData[], allSelected: boolean } · single: { selected: TreeNodeData | null }On any selection change.
sp-expand{ node: TreeNodeData }A row expands.
sp-collapse{ node: TreeNodeData }A row collapses.
sp-load-error{ node: TreeNodeData, error: Error }A lazy load rejects.

The multi-mode sp-change reports the concrete checked nodes plus allSelected — there is no sentinel “ALL” node in the payload (that was v3; see migration).

The full WAI-ARIA tree pattern with a roving tabindex:

KeyAction
/ Move focus to the next / previous visible row
Expand a collapsed branch, else move into the first child
Collapse an expanded branch, else move to the parent
Home / EndFirst / last visible row
Enter / SpaceToggle check (multi) / select (single)
printable charactersType-ahead to the next matching label

ARIA: role="tree"/treeitem, aria-level, aria-setsize, aria-posinset, aria-expanded, aria-checked (including "mixed"), aria-disabled, aria-busy.

tree, row, all-row, toggle, checkbox, radio, label, match, spinner, error, retry, search, search-input, search-clear, empty.

sp-tree::part(row) { padding-block: 2px; }
sp-tree::part(match) { background: gold; }

Tokens and a worked dark theme: Theming.