Search documentation

Type to search the documentation.

API: Primitives

TreeService

Service reference for TreeService.

Overview

Properties

Name Type Description
readonly nodes Signal<TreeNode<unknown>[]>
readonly expandedIds Signal<Set<string>>
readonly selectedIds Signal<Set<string>>
readonly activeId Signal<string | null>
readonly config Signal<TreeConfig> Resolved configuration (defaults merged with the config input).
readonly loadStates Signal<ReadonlyMap<string, TreeNodeLoadState>> Per-node lazy-load state. Nodes never lazily loaded are absent from the map.
readonly visibleNodes Signal<FlatTreeNode[]> Visible nodes (respecting expansion) in top-to-bottom traversal order.
readonly selectedNodes Signal<TreeNode<unknown>[]>

Public methods

init

init(nodes: TreeNode[], config?: Partial<TreeConfig>): void
Parameter Type Optional Description
nodes TreeNode[]
config Partial<TreeConfig> Yes

hasChildren

hasChildren(node: TreeNode): boolean

Whether a node can be expanded. children wins when present; otherwise the hasChildren flag lets a node declare children it has not loaded yet.

Parameter Type Optional Description
node TreeNode

findNode

findNode(id: string): TreeNode | null

Depth-first lookup by id over the current (possibly lazily-extended) tree.

Parameter Type Optional Description
id string

isExpanded

isExpanded(id: string): boolean
Parameter Type Optional Description
id string

isSelected

isSelected(id: string): boolean
Parameter Type Optional Description
id string

toggle

toggle(id: string): void
Parameter Type Optional Description
id string

expand

expand(id: string): void
Parameter Type Optional Description
id string

collapse

collapse(id: string): void
Parameter Type Optional Description
id string

expandAll

expandAll(): void

Expand every node whose children are already loaded. Deliberately does not trigger loadChildren — "expand all" must not mean "download the whole tree".

collapseAll

collapseAll(): void

setLoadChildren

setLoadChildren(fn: TreeLoadChildrenFn | null): void

Install (or remove) the children loader. Safe to call repeatedly with a new function identity — it does not reset expansion or selection. Setting a loader while nodes are already expanded starts the loads those nodes are waiting for.

Parameter Type Optional Description
fn TreeLoadChildrenFn | null

loadState

loadState(nodeOrId: TreeNode | string): TreeNodeLoadState

Load state of a node. Nodes that already carry a children array report loaded, so templates can treat static and lazily-loaded nodes the same way.

Parameter Type Optional Description
nodeOrId TreeNode | string

isLoading

isLoading(nodeOrId: TreeNode | string): boolean
Parameter Type Optional Description
nodeOrId TreeNode | string

loadError

loadError(nodeOrId: TreeNode | string): unknown

The rejection value of the last failed load, or undefined.

Parameter Type Optional Description
nodeOrId TreeNode | string

retry

retry(nodeOrId: TreeNode | string): void

Clear the error state and re-issue the request, expanding the node again.

Parameter Type Optional Description
nodeOrId TreeNode | string

select

select(id: string): void
Parameter Type Optional Description
id string

deselect

deselect(id: string): void
Parameter Type Optional Description
id string

toggleSelection

toggleSelection(id: string): void
Parameter Type Optional Description
id string

clearSelection

clearSelection(): void

setActive

setActive(id: string): void

Mark a node as the active (focused) treeitem for roving tabindex.

Parameter Type Optional Description
id string

focusNext

focusNext(id: string): void

Move focus to the next visible node (ArrowDown).

Parameter Type Optional Description
id string

focusPrevious

focusPrevious(id: string): void

Move focus to the previous visible node (ArrowUp).

Parameter Type Optional Description
id string

focusFirst

focusFirst(): void

Move focus to the first visible node (Home).

focusLast

focusLast(): void

Move focus to the last visible node (End).

focusParent

focusParent(id: string): void

Move focus to the parent node (ArrowLeft on a collapsed/leaf node).

Parameter Type Optional Description
id string

focusFirstChild

focusFirstChild(id: string): void

Move focus to the first child (ArrowRight on an expanded node).

Parameter Type Optional Description
id string

typeahead

typeahead(char: string, currentId: string | null): void

Type-ahead: focus the next visible node whose label starts with the typed characters. Consecutive keystrokes within TYPEAHEAD_RESET_MS build up a search string; a single repeated letter cycles through matches.

Parameter Type Optional Description
char string
currentId string | null