Skip to main content
Neural UIv2.0.0Documentation
View v1 GitHub

Tree

Explore hierarchical data with controlled expansion, selection and optional reordering.

Category
Data and hierarchy
Import
@neural-ui/core/tree
Selector
neu-tree
import { NeuTreeComponent } from '@neural-ui/core/tree';

Usage

nodes supplies flat records with stable keys and data; hierarchy describes roots and loaded/unloaded child relations. Apply expandedKeysChange.keys to expandedKeys and selectionChange.selection to selection. childrenRequest identifies an unloaded parent and request; the application loads children and replaces nodes/hierarchy. nodeMove is a proposal: update hierarchy to accept it. A Template receives node data, not the wrapper node.

Examples

Try this application-owned interaction. Its event handling and initial data are included in Code.

Examples
Workspace
Design
Engineering
Archive

Events: 0

Try and configure

Change the public options, try the result and inspect the updated template. Code contains the complete executable implementation.

Try and configure
Workspace
Design
Engineering
Archive

Events: 0

template.html
<neu-tree
  [nodes]="nodes()"
  [hierarchy]="hierarchy()"
  [expandedKeys]="expanded()"
  (expandedKeysChange)="
    expanded.set($event.keys); record('expandedKeysChange', $event)
  "
  [selectionMode]="'checkbox'"
  [selection]="selection()"
  (selectionChange)="acceptSelection($event.selection)"
  [searchable]="true"
  [reorderable]="false"
  [retryLabel]="'Retry loading'"
  (nodeAction)="record('nodeAction', $event)"
  (childrenRequest)="requestChildren($event)"
  (nodeMove)="acceptMove($event)"
  [ariaLabel]="'Project folders'"
  [collapseLabel]="'Collapse folder'"
  [emptyLabel]="'No folders'"
  [expandLabel]="'Expand folder'"
  [invalidTreeLabel]="'Invalid tree data'"
  [searchLabel]="'Search folders'"
></neu-tree>

State and events

nodes supplies flat records with stable keys and data; hierarchy describes roots and loaded/unloaded child relations. Apply expandedKeysChange.keys to expandedKeys and selectionChange.selection to selection. childrenRequest identifies an unloaded parent and request; the application loads children and replaces nodes/hierarchy. nodeMove is a proposal: update hierarchy to accept it. A Template receives node data, not the wrapper node.

Accessibility and keyboard

Arrow keys traverse and expand/collapse nodes; Home/End reach the first/last visible node. Space changes selection. Reordering has keyboard alternatives when enabled.

Key
Action
Tab Reach the tree and its enabled controls.
ArrowDown / ArrowUp Focus the next or previous visible node.
ArrowRight / ArrowLeft Expand, enter, collapse or leave a branch; horizontal direction follows RTL.
Home Focus the first visible node.
End Focus the last visible node.
Enter Activate selection for the focused node when selection is enabled.
Space Activate selection for the focused node when selection is enabled.

API

Inputs, models and Outputs are extracted from the installed Core package. Named public types link to their definitions. Templates below include executable examples.

Inputs

Configure the component with [property]="value". Your application supplies these values; the component does not replace the state you pass in.

Name
Type
Default
Template binding
Description
ariaLabelstring'Tree'[ariaLabel]Accessible name of the tree.
collapseLabelstring'Collapse node'[collapseLabel]Accessible label of the toggle in expanded mode.
emptyLabelstring'No nodes available'[emptyLabel]Label for empty collection. Translate it for your application.
expandedKeysreadonly K[][][expandedKeys]Applied keys of expanded branches. Expansion changes are proposed to the application.
expandLabelstring'Expand node'[expandLabel]Accessible label of the toggle in collapsed mode.
hierarchyNeuTreeHierarchy<K>Required[hierarchy]Roots and child relations, with loaded/loading/error/unloaded state and revision identities.
indentSizenumber18[indentSize]Horizontal indentation per tree level in pixels.
invalidTreeLabelstring'Tree data is invalid'[invalidTreeLabel]Accessible diagnostic text when hierarchy data is inconsistent.
nodesreadonly NeuTreeNode<T, K>[]Required[nodes]Flat keyed node records. The separate hierarchy defines their parent/child relationships.
reorderablebooleanfalse[reorderable]Enable tree node move proposals; the application still owns the hierarchy.
retryLabelstring'Retry loading'[retryLabel]Visible or accessible label for retrying a failed load/upload.
searchablebooleanfalse[searchable]Shows the built-in search field.
searchLabelstring'Search nodes'[searchLabel]Accessible label or placeholder of the search field.
selectionNeuTreeSelection<K>{ mode: 'none' }[selection]Applied discriminated selection state: none, single, multiple or checkbox.
virtualizationNeuTreeVirtualization | nullnull[virtualization]Virtual tree viewport configuration, or null for normal rendering.

Outputs

Listen to an event with (event)="handler($event)". The table explains the data your handler receives and how to use it.

Name
Payload
Template binding
Description
childrenRequestNeuTreeChildrenRequest<K>(childrenRequest)="onChildrenRequest($event)"Requests children using parentKey, requestId and hierarchyRevision. Load records and update nodes/hierarchy.
expandedKeysChangeNeuTreeExpandedKeysChange<K>(expandedKeysChange)="onExpandedKeysChange($event)"Proposes the next branch keys. Update expandedKeys to accept a controlled change.
nodeActionNeuTreeNodeAction<K>(nodeAction)="onNodeAction($event)"Emits the stable key of the activated node.
nodeMoveNeuTreeNodeMove<K>(nodeMove)="onNodeMove($event)"Proposes a move with source/target keys and position. Replace hierarchy to accept it.
selectionChangeNeuTreeSelectionChange<K>(selectionChange)="onSelectionChange($event)"Proposes selection together with the affected key and interaction source. Apply payload.selection to selection.

Templates

ng-content projects content into the component. TemplateRef inputs receive a template; ng-template directives identify templates with a typed context. A directive shared by an entrypoint is not necessarily a slot of this component.

Name
Mechanism
Contract
NeuTreeNodeDirectiveView example Public template directive (entrypoint)ng-template[neuTreeNode]

Each example demonstrates a different template. Switch between Demo and Code to inspect its implementation, imports and state.

NeuTreeNodeDirective

NeuTreeNodeDirective

NeuTreeNodeDirective
WorkspaceLevel 1 ยท โ€”
DesignLevel 2 ยท โ€”
EngineeringLevel 2 ยท โ€”
ArchiveLevel 1 ยท โ€”

Events: 0

Public Types

Open a type to inspect its definition and interface fields.

Styles and tokens

Use the supported public tokens listed below. Surrounding layout belongs to your application; validate the result in light and dark modes and narrow containers.

Specific tokens

This component uses shared theme tokens rather than dedicated component hooks.

Shared tokens used

Override these on a local wrapper to affect this example. An override on :root affects other components that use the same token.

Token
Purpose here
Other impact
Default / fallback
--neu-border Normal control and cell borders Shared by other Core consumers; scope the override. rgba(15, 23, 42, 0.08)
--neu-focus-ring Normal keyboard-focus ring Shared by other Core consumers; scope the override. 0 0 0 var(--neu-focus-ring-width) rgba(0, 122, 255, 0.15)
--neu-primary Brand color for active controls and emphasis Shared by other Core consumers; scope the override. #007aff
--neu-primary-dark Dark brand shade; outline and ghost Button text in the light theme Shared by other Core consumers; scope the override. #005fcc
--neu-primary-light Light brand shade; outline and ghost Button text in the dark theme Shared by other Core consumers; scope the override. #339dff
--neu-surface Main field, header or control surface Shared by other Core consumers; scope the override. #ffffff
--neu-surface-2 Secondary surfaces and alternating rows Shared by other Core consumers; scope the override. #f1f5f9
--neu-text Main text and inherited icon color Shared by other Core consumers; scope the override. #0f172a