Tree

Tree components display hierarchical data in a collapsible structure, allowing users to explore nested relationships while keeping the interface organized and navigable.

import {TreeModule} from "@qualcomm-ui/angular/tree"

Overview

  • The tree relies on the TreeCollection class to manage its items. Refer to the API below for details.
  • Trees are composed of nodes, which are objects that describe the tree data. There are two types of nodes:
    • A branch node is a node that has children.
    • A leaf node is a node that does not have children.
  • Each node has a value (unique identifier used for selection/expansion) and a text (display text).

Default object shape:

  • value (required): unique identifier for expansion/selection
  • text (required): display text
  • nodes (optional): child nodes for branches
  • disabled (optional): prevents interaction when true

These defaults can be overridden in the TreeCollection constructor.

Examples

Node Shorthand

We expose the q-tree-nodes component for rendering Branch and Leaf nodes. Use the <ng-template q-tree-branch-template> and <ng-template q-tree-leaf-template> directives to customize the content of each tree item.

Note that q-tree-nodes automatically renders child nodes for branches, so you only have to customize the content of the node itself.

prettier.config.js
package.json
tsconfig.json
<q-tree-nodes [indexPath]="[i]" [node]="node">
  <ng-template
    let-branch
    q-tree-branch-template
    [rootNode]="collection.rootNode"
  >
    <div q-tree-branch-node>
      <div q-tree-branch-trigger></div>
      <svg q-tree-node-icon qIcon="FolderIcon"></svg>
      <span q-tree-node-text>{{ branch.node.name }}</span>
    </div>
  </ng-template>

  <ng-template
    let-leaf
    q-tree-leaf-template
    [rootNode]="collection.rootNode"
  >
    <div q-tree-leaf-node>
      <div q-tree-node-indicator></div>
      <svg q-tree-node-icon qIcon="FileText"></svg>
      <span q-tree-node-text>{{ leaf.node.name }}</span>
    </div>
  </ng-template>
</q-tree-nodes>

Node Types

Pass the rootNode input to the template directives to enable TypeScript type inference. This allows branch.node and leaf.node to have your custom node type instead of the generic TreeNode type.

Nodes

You can bring your own recursive component to create your own abstraction for the tree.

NOTE

This approach is recommended only for advanced use cases. Most users should use the shorthand q-tree-nodes instead.

prettier.config.js
package.json
tsconfig.json
import {Component, computed, inject, input, type OnInit} from "@angular/core"
import {FileText, FolderIcon} from "lucide-angular"

import {IconDirective} from "@qualcomm-ui/angular/icon"
import {TreeModule} from "@qualcomm-ui/angular/tree"
import {provideIcons} from "@qualcomm-ui/angular-core/lucide"
import {
  provideTreeNodePropsContext,
  provideTreeNodeStateContext,
  TreeNodePropsContextService,
  TreeNodeStateContextService,
  useTreeContext,
} from "@qualcomm-ui/angular-core/tree"
import {createTreeCollection, type NodeProps} from "@qualcomm-ui/core/tree"

interface FileNode {
  id: string
  name: string
  nodes?: FileNode[]
}

const collection = createTreeCollection<FileNode>({
  nodeChildren: "nodes",
  nodeText: (node) => node.name,
  nodeValue: (node) => node.id,
  rootNode: {
    id: "ROOT",
    name: "",
    nodes: [
      {
        id: "node_modules",
        name: "node_modules",
        nodes: [
          {
            id: "@qui",
            name: "@qui",
            nodes: [
              {
                id: "node_modules/@qualcomm-ui/core",
                name: "@qualcomm-ui/core",
              },
              {
                id: "node_modules/@qualcomm-ui/react",
                name: "@qualcomm-ui/react",
              },
              {
                id: "node_modules/@qualcomm-ui/react-core",
                name: "@qualcomm-ui/react-core",
              },
            ],
          },
          {
            id: "node_modules/@types",
            name: "@types",
            nodes: [
              {id: "node_modules/@types/react", name: "react"},
              {id: "node_modules/@types/react-dom", name: "react-dom"},
            ],
          },
        ],
      },
      {
        id: "src",
        name: "src",
        nodes: [
          {id: "src/app.tsx", name: "app.tsx"},
          {id: "src/index.ts", name: "index.ts"},
        ],
      },
      {id: "prettier.config.js", name: "prettier.config.js"},
      {id: "package.json", name: "package.json"},
      {id: "tsconfig.json", name: "tsconfig.json"},
    ],
  },
})

@Component({
  imports: [TreeModule, IconDirective],
  providers: [
    provideIcons({FileText, FolderIcon}),
    provideTreeNodePropsContext(),
    provideTreeNodeStateContext(),
  ],
  selector: "tree-nodes-recursive",
  template: `
    @let childNodes = treeContext().collection.getNodeChildren(node());
    @if (childNodes.length) {
      <div q-tree-branch>
        <div q-tree-branch-node>
          <div q-tree-node-indicator></div>
          <div q-tree-branch-trigger></div>
          <svg q-tree-node-icon qIcon="FolderIcon"></svg>
          <span q-tree-node-text>
            {{ treeContext().collection.stringifyNode(node()) }}
          </span>
        </div>
        <div q-tree-branch-content>
          <div q-tree-branch-indent-guide></div>
          @for (
            childNode of childNodes;
            let j = $index;
            track treeContext().collection.getNodeValue(childNode)
          ) {
            <tree-nodes-recursive
              [indexPath]="indexPath().concat(j)"
              [node]="childNode"
            />
          }
        </div>
      </div>
    } @else {
      <div q-tree-leaf-node>
        <div q-tree-node-indicator></div>
        <svg q-tree-node-icon qIcon="FileText"></svg>
        <span q-tree-node-text>
          {{ treeContext().collection.stringifyNode(node()) }}
        </span>
      </div>
    }
  `,
})
export class TreeNodesRecursive implements OnInit {
  readonly indexPath = input.required<number[]>()
  readonly node = input.required<FileNode>()

  protected readonly treeContext = useTreeContext()

  private readonly nodePropsService = inject(TreeNodePropsContextService)
  private readonly nodeStateService = inject(TreeNodeStateContextService)

  ngOnInit() {
    const nodeProps = computed<NodeProps<FileNode>>(() => ({
      indexPath: this.indexPath(),
      node: this.node(),
    }))
    this.nodePropsService.init(nodeProps)
    this.nodeStateService.init(
      computed(() => this.treeContext().getNodeState(nodeProps())),
    )
  }
}

@Component({
  imports: [TreeModule, TreeNodesRecursive],
  providers: [provideIcons({FileText, FolderIcon})],
  selector: "tree-nodes-demo",
  template: `
    <div class="w-full max-w-sm" q-tree-root [collection]="collection">
      @for (
        node of collection.rootNode.nodes;
        let i = $index;
        track collection.getNodeValue(node)
      ) {
        <tree-nodes-recursive [indexPath]="[i]" [node]="node" />
      }
    </div>
  `,
})
export class TreeNodesDemo {
  collection = collection
}

Default Expanded

Expand nodes by default using the defaultExpandedValue input. Or use expandedValue and expandedValueChange to control the expansion manually. These inputs follow our controlled state pattern.

src
app.tsx
index.ts
prettier.config.js
package.json
tsconfig.json
<div
  class="w-full max-w-sm"
  q-tree-root
  [collection]="collection"
  [defaultExpandedValue]="['src']"
>

Checkbox Trees

Use the q-tree-node-checkbox directive within each node to create a checkbox tree. The checked state of the tree can be controlled using the checkedValue, checkedValueChange, and defaultCheckedValue inputs, which follow our controlled state pattern.

Qualcomm
Intel
AMD
import {Component} from "@angular/core"

import {TreeModule} from "@qualcomm-ui/angular/tree"
import {createTreeCollection} from "@qualcomm-ui/core/tree"

interface Node {
  id: string
  nodes?: Node[]
  text: string
}

@Component({
  imports: [TreeModule],
  selector: "tree-checkbox-demo",
  template: `
    <div
      class="w-full max-w-sm"
      q-tree-root
      [collection]="collection"
      [defaultExpandedValue]="['qualcomm', 'amd', 'intel']"
    >
      @for (
        node of collection.rootNode.nodes;
        let i = $index;
        track collection.getNodeValue(node)
      ) {
        <q-tree-nodes [indexPath]="[i]" [node]="node">
          <ng-template
            let-branch
            q-tree-branch-template
            [rootNode]="collection.rootNode"
          >
            <div q-tree-branch-node>
              <div q-tree-branch-trigger></div>
              <span q-tree-node-checkbox></span>
              <span q-tree-node-text>{{ branch.node.text }}</span>
            </div>
          </ng-template>

          <ng-template
            let-leaf
            q-tree-leaf-template
            [rootNode]="collection.rootNode"
          >
            <div q-tree-leaf-node>
              <div q-tree-node-indicator></div>
              <span q-tree-node-checkbox></span>
              <span q-tree-node-text>{{ leaf.node.text }}</span>
            </div>
          </ng-template>
        </q-tree-nodes>
      }
    </div>
  `,
})
export class TreeCheckboxDemo {
  collection = createTreeCollection<Node>({
    nodeText: "text",
    nodeValue: "id",
    rootNode: {
      id: "ROOT",
      nodes: [
        {
          id: "qualcomm",
          nodes: [
            {
              id: "snapdragon_x_elite",
              nodes: [
                {id: "X1E-00-1DE", text: "12-core X1E-00-1DE"},
                {id: "X1E-84-100", text: "12-core X1E-84-100"},
                {id: "X1E-80-100", text: "12-core X1E-80-100"},
                {id: "X1E-78-100", text: "12-core X1E-78-100"},
              ],
              text: "Snapdragon X Elite",
            },
            {
              id: "snapdragon_x_plus",
              nodes: [
                {id: "X1P-66-100", text: "10-core X1P-66-100"},
                {id: "X1P-64-100", text: "10-core X1P-64-100"},
                {id: "X1P-46-100", text: "8-core Plus X1P-46-100"},
                {id: "X1P-42-100", text: "8-core Plus X1P-42-100"},
              ],
              text: "Snapdragon X Plus",
            },
          ],
          text: "Qualcomm",
        },
        {
          id: "intel",
          nodes: [
            {
              id: "intel_core_ultra",
              nodes: [
                {id: "ultra9_s2", text: "Core Ultra 9 (Series 2)"},
                {id: "ultra7_s2", text: "Core Ultra 7 (Series 2)"},
                {id: "ultra5_s2", text: "Core Ultra 5 (Series 2)"},
              ],
              text: "Intel Core Ultra",
            },
            {
              id: "intel_core_i9",
              nodes: [
                {id: "i9_14th", text: "Core i9 14th Gen"},
                {id: "i9_13th", text: "Core i9 13th Gen"},
              ],
              text: "Intel Core i9",
            },
            {
              id: "intel_core_i7",
              nodes: [
                {id: "i7_14th", text: "Core i7 14th Gen"},
                {id: "i7_13th", text: "Core i7 13th Gen"},
              ],
              text: "Intel Core i7",
            },
            {
              id: "intel_core_i5",
              nodes: [
                {id: "i5_14th", text: "Core i5 14th Gen"},
                {id: "i5_13th", text: "Core i5 13th Gen"},
              ],
              text: "Intel Core i5",
            },
            {
              id: "intel_core_i3",
              nodes: [
                {id: "i3_14th", text: "Core i3 14th Gen"},
                {id: "i3_13th", text: "Core i3 13th Gen"},
              ],
              text: "Intel Core i3",
            },
          ],
          text: "Intel",
        },
        {
          id: "amd",
          nodes: [
            {
              id: "amd_threadripper",
              nodes: [
                {
                  id: "threadripper_9000",
                  text: "Ryzen Threadripper 9000 Series",
                },
                {
                  id: "threadripper_7000",
                  text: "Ryzen Threadripper 7000 Series",
                },
              ],
              text: "AMD Threadripper",
            },
            {
              id: "amd_ryzen_9",
              nodes: [
                {id: "ryzen9_9000", text: "Ryzen 9 9000 Series"},
                {id: "ryzen9_7000", text: "Ryzen 9 7000 Series"},
              ],
              text: "AMD Ryzen 9",
            },
            {
              id: "amd_ryzen_7_5",
              nodes: [
                {id: "ryzen7_9000", text: "Ryzen 7 9000 Series"},
                {id: "ryzen7_8000g", text: "Ryzen 7 8000-G Series"},
                {id: "ryzen7_8000", text: "Ryzen 7 8000 Series"},
                {id: "ryzen7_7000", text: "Ryzen 7 7000 Series"},
                {id: "ryzen5_9000", text: "Ryzen 5 9000 Series"},
                {id: "ryzen5_8000g", text: "Ryzen 5 8000-G Series"},
                {id: "ryzen5_8000", text: "Ryzen 5 8000 Series"},
                {id: "ryzen5_7000", text: "Ryzen 5 7000 Series"},
              ],
              text: "AMD Ryzen 7 / 5",
            },
          ],
          text: "AMD",
        },
      ],
      text: "",
    },
  })
}

Checkbox selection state

The Tree handles nested checkbox selection automatically:

  • If all of a node's children are checked, the node will also be checked.
  • If only some of a node's children are checked, the node will appear indeterminate to indicate partial selection.

When you supply the checkedValue or defaultCheckedValue inputs, you must account for the above logic.

The following demo shows checked state below the tree. Interact with it to see state updates:

qualcomm
intel
amd
[
  "X1E-00-1DE",
  "X1E-84-100"
]
<q-tree-nodes [indexPath]="[i]" [node]="node">
  <ng-template
    let-branch
    q-tree-branch-template
    [rootNode]="collection.rootNode"
  >
    <div q-tree-branch-node>
      <div q-tree-branch-trigger></div>
      <span q-tree-node-checkbox></span>
      <span q-tree-node-text>{{ branch.node.id }}</span>
    </div>
  </ng-template>

  <ng-template
    let-leaf
    q-tree-leaf-template
    [rootNode]="collection.rootNode"
  >
    <div q-tree-leaf-node>
      <span q-tree-node-checkbox></span>
      <span q-tree-node-text>{{ leaf.node.id }}</span>
    </div>
  </ng-template>
</q-tree-nodes>

Disabled Nodes

You can disable nodes by setting the disabled property on the node object.

prettier.config.js
package.json
renovate.json
tsconfig.json
import {Component} from "@angular/core"
import {FileText, FolderIcon} from "lucide-angular"

import {IconDirective} from "@qualcomm-ui/angular/icon"
import {TreeModule} from "@qualcomm-ui/angular/tree"
import {provideIcons} from "@qualcomm-ui/angular-core/lucide"
import {createTreeCollection} from "@qualcomm-ui/core/tree"

interface FileNode {
  disabled?: boolean
  id: string
  name: string
  nodes?: FileNode[]
}

@Component({
  imports: [TreeModule, IconDirective],
  providers: [provideIcons({FileText, FolderIcon})],
  selector: "tree-disabled-node-demo",
  template: `
    <div class="w-full max-w-sm" q-tree-root [collection]="collection">
      @for (
        node of collection.rootNode.nodes;
        let i = $index;
        track collection.getNodeValue(node)
      ) {
        <q-tree-nodes [indexPath]="[i]" [node]="node">
          <ng-template
            let-branch
            q-tree-branch-template
            [rootNode]="collection.rootNode"
          >
            <div q-tree-branch-node>
              <div q-tree-node-indicator></div>
              <div q-tree-branch-trigger></div>
              <svg q-tree-node-icon qIcon="FolderIcon"></svg>
              <span q-tree-node-text>{{ branch.node.name }}</span>
            </div>
          </ng-template>

          <ng-template
            let-leaf
            q-tree-leaf-template
            [rootNode]="collection.rootNode"
          >
            <div q-tree-leaf-node>
              <div q-tree-node-indicator></div>
              <svg q-tree-node-icon qIcon="FileText"></svg>
              <span q-tree-node-text>{{ leaf.node.name }}</span>
            </div>
          </ng-template>
        </q-tree-nodes>
      }
    </div>
  `,
})
export class TreeDisabledNodeDemo {
  collection = createTreeCollection<FileNode>({
    nodeChildren: "nodes",
    nodeText: (node) => node.name,
    nodeValue: (node) => node.id,
    rootNode: {
      id: "ROOT",
      name: "",
      nodes: [
        {
          id: "node_modules",
          name: "node_modules",
          nodes: [
            {
              id: "@qui",
              name: "@qui",
              nodes: [
                {
                  id: "node_modules/@qualcomm-ui/core",
                  name: "@qualcomm-ui/core",
                },
                {
                  id: "node_modules/@qualcomm-ui/react",
                  name: "@qualcomm-ui/react",
                },
                {
                  id: "node_modules/@qualcomm-ui/react-core",
                  name: "@qualcomm-ui/react-core",
                },
              ],
            },
            {
              id: "node_modules/@types",
              name: "@types",
              nodes: [
                {id: "node_modules/@types/react", name: "react"},
                {id: "node_modules/@types/react-dom", name: "react-dom"},
              ],
            },
          ],
        },
        {
          id: "src",
          name: "src",
          nodes: [
            {id: "src/app.tsx", name: "app.tsx"},
            {id: "src/index.ts", name: "index.ts"},
          ],
        },
        {id: "prettier.config.js", name: "prettier.config.js"},
        {id: "package.json", name: "package.json"},
        {disabled: true, id: "renovate.json", name: "renovate.json"},
        {id: "tsconfig.json", name: "tsconfig.json"},
      ],
    },
  })
}

Filtering

Here's an example that filters the nodes using matchSorter.

prettier.config.js
package.json
tsconfig.json
import {Component, signal} from "@angular/core"
import {FormsModule} from "@angular/forms"
import {FileText, FolderIcon, Search} from "lucide-angular"

import {IconDirective} from "@qualcomm-ui/angular/icon"
import {TextInputModule} from "@qualcomm-ui/angular/text-input"
import {TreeModule} from "@qualcomm-ui/angular/tree"
import {provideIcons} from "@qualcomm-ui/angular-core/lucide"
import {createTreeCollection} from "@qualcomm-ui/core/tree"
import type {TreeCollection} from "@qualcomm-ui/utils/collection"
import {matchSorter} from "@qualcomm-ui/utils/match-sorter"

interface FileNode {
  id: string
  name: string
  nodes?: FileNode[]
}

const initialCollection = createTreeCollection<FileNode>({
  nodeChildren: "nodes",
  nodeText: (node) => node.name,
  nodeValue: (node) => node.id,
  rootNode: {
    id: "ROOT",
    name: "",
    nodes: [
      {
        id: "node_modules",
        name: "node_modules",
        nodes: [
          {
            id: "@qui",
            name: "@qui",
            nodes: [
              {
                id: "node_modules/@qualcomm-ui/core",
                name: "@qualcomm-ui/core",
              },
              {
                id: "node_modules/@qualcomm-ui/react",
                name: "@qualcomm-ui/react",
              },
              {
                id: "node_modules/@qualcomm-ui/react-core",
                name: "@qualcomm-ui/react-core",
              },
            ],
          },
          {
            id: "node_modules/@types",
            name: "@types",
            nodes: [
              {id: "node_modules/@types/react", name: "react"},
              {id: "node_modules/@types/react-dom", name: "react-dom"},
            ],
          },
        ],
      },
      {
        id: "src",
        name: "src",
        nodes: [
          {id: "src/app.tsx", name: "app.tsx"},
          {id: "src/index.ts", name: "index.ts"},
        ],
      },
      {id: "prettier.config.js", name: "prettier.config.js"},
      {id: "package.json", name: "package.json"},
      {id: "tsconfig.json", name: "tsconfig.json"},
    ],
  },
})

@Component({
  imports: [TreeModule, IconDirective, TextInputModule, FormsModule],
  providers: [provideIcons({FileText, FolderIcon, Search})],
  selector: "tree-filtering-demo",
  template: `
    <div
      class="w-full max-w-sm"
      q-tree-root
      [collection]="initialCollection"
      [expandedValue]="expanded()"
      (expandedValueChanged)="expanded.set($event.expandedValue)"
    >
      <q-text-input
        class="mb-1"
        placeholder="Search for files: 'react'"
        size="sm"
        startIcon="Search"
        [ngModel]="query()"
        (ngModelChange)="search($event)"
      />
      @for (
        node of collection().rootNode.nodes;
        let i = $index;
        track collection().getNodeValue(node)
      ) {
        <q-tree-nodes [indexPath]="[i]" [node]="node">
          <ng-template
            let-branch
            q-tree-branch-template
            [rootNode]="collection().rootNode"
          >
            <div q-tree-branch-node>
              <div q-tree-node-indicator></div>
              <div q-tree-branch-trigger></div>
              <svg q-tree-node-icon qIcon="FolderIcon"></svg>
              <span q-tree-node-text>{{ branch.node.name }}</span>
            </div>
          </ng-template>

          <ng-template
            let-leaf
            q-tree-leaf-template
            [rootNode]="collection().rootNode"
          >
            <div q-tree-leaf-node>
              <div q-tree-node-indicator></div>
              <svg q-tree-node-icon qIcon="FileText"></svg>
              <span q-tree-node-text>{{ leaf.node.name }}</span>
            </div>
          </ng-template>
        </q-tree-nodes>
      }
    </div>
  `,
})
export class TreeFilteringDemo {
  readonly initialCollection = initialCollection
  readonly collection = signal<TreeCollection<FileNode>>(initialCollection)
  readonly expanded = signal<string[]>([])
  readonly query = signal("")

  search(value: string) {
    this.query.set(value)

    if (!value) {
      this.collection.set(initialCollection)
      return
    }

    const nodes = matchSorter(initialCollection.getDescendantNodes(), value, {
      keys: ["name"],
    })
    const nextCollection = initialCollection.filter((node) =>
      nodes.some((n) => n.id === node.id),
    )
    this.collection.set(nextCollection)
    this.expanded.set(nextCollection.getBranchValues())
  }
}

Tree nodes can be links using Angular's RouterLink directive. Apply the q-tree-branch-node or q-tree-leaf-node directive to an anchor element with [routerLink].

@if (leaf.node.pathname) {
  <a q-tree-leaf-node [routerLink]="leaf.node.pathname">
    <div q-tree-node-indicator></div>
    <span q-tree-node-text>{{ leaf.node.name }}</span>
  </a>
} @else {
  <div q-tree-leaf-node>
    <div q-tree-node-indicator></div>
    <span q-tree-node-text>{{ leaf.node.name }}</span>
  </div>
}

Sizes

Tree item sizes are controlled using the size input on the root of the tree.

Small (sm)
prettier.config.js
package.json
tsconfig.json
Medium (md)
prettier.config.js
package.json
tsconfig.json
import {NgTemplateOutlet} from "@angular/common"
import {Component} from "@angular/core"
import {FileText, FolderIcon} from "lucide-angular"

import {IconDirective} from "@qualcomm-ui/angular/icon"
import {TreeModule} from "@qualcomm-ui/angular/tree"
import {provideIcons} from "@qualcomm-ui/angular-core/lucide"
import {createTreeCollection} from "@qualcomm-ui/core/tree"

interface FileNode {
  id: string
  name: string
  nodes?: FileNode[]
}

const collection = createTreeCollection<FileNode>({
  nodeChildren: "nodes",
  nodeText: (node) => node.name,
  nodeValue: (node) => node.id,
  rootNode: {
    id: "ROOT",
    name: "",
    nodes: [
      {
        id: "node_modules",
        name: "node_modules",
        nodes: [
          {
            id: "@qui",
            name: "@qui",
            nodes: [
              {
                id: "node_modules/@qualcomm-ui/core",
                name: "@qualcomm-ui/core",
              },
              {
                id: "node_modules/@qualcomm-ui/react",
                name: "@qualcomm-ui/react",
              },
              {
                id: "node_modules/@qualcomm-ui/react-core",
                name: "@qualcomm-ui/react-core",
              },
            ],
          },
          {
            id: "node_modules/@types",
            name: "@types",
            nodes: [
              {id: "node_modules/@types/react", name: "react"},
              {id: "node_modules/@types/react-dom", name: "react-dom"},
            ],
          },
        ],
      },
      {
        id: "src",
        name: "src",
        nodes: [
          {id: "src/app.tsx", name: "app.tsx"},
          {id: "src/index.ts", name: "index.ts"},
        ],
      },
      {id: "prettier.config.js", name: "prettier.config.js"},
      {id: "package.json", name: "package.json"},
      {id: "tsconfig.json", name: "tsconfig.json"},
    ],
  },
})

@Component({
  imports: [TreeModule, IconDirective, NgTemplateOutlet],
  providers: [provideIcons({FileText, FolderIcon})],
  selector: "tree-size-demo",
  template: `
    <div class="flex w-full flex-col gap-4">
      <div
        #root1="treeRoot"
        class="w-full max-w-sm"
        q-tree-root
        size="sm"
        [collection]="collection"
      >
        <span q-tree-label>Small (sm)</span>
        <ng-container
          [ngTemplateOutlet]="treeContent"
          [ngTemplateOutletInjector]="root1.injector"
        />
      </div>

      <div
        #root2="treeRoot"
        class="w-full max-w-sm"
        q-tree-root
        size="md"
        [collection]="collection"
      >
        <span q-tree-label>Medium (md)</span>
        <ng-container
          [ngTemplateOutlet]="treeContent"
          [ngTemplateOutletInjector]="root2.injector"
        />
      </div>
    </div>

    <ng-template #treeContent>
      @for (
        node of collection.rootNode.nodes;
        let i = $index;
        track collection.getNodeValue(node)
      ) {
        <q-tree-nodes [indexPath]="[i]" [node]="node">
          <ng-template
            let-branch
            q-tree-branch-template
            [rootNode]="collection.rootNode"
          >
            <div q-tree-branch-node>
              <div q-tree-node-indicator></div>
              <div q-tree-branch-trigger></div>
              <svg q-tree-node-icon qIcon="FolderIcon"></svg>
              <span q-tree-node-text>{{ branch.node.name }}</span>
            </div>
          </ng-template>

          <ng-template
            let-leaf
            q-tree-leaf-template
            [rootNode]="collection.rootNode"
          >
            <div q-tree-leaf-node>
              <div q-tree-node-indicator></div>
              <svg q-tree-node-icon qIcon="FileText"></svg>
              <span q-tree-node-text>{{ leaf.node.name }}</span>
            </div>
          </ng-template>
        </q-tree-nodes>
      }
    </ng-template>
  `,
})
export class TreeSizeDemo {
  collection = collection
}

Add / Remove nodes

The TreeCollection class exposes methods to handle the addition and removal of nodes. Here's an example of how to use them.

prettier.config.js
package.json
tsconfig.json
import {Component, input, output, signal} from "@angular/core"
import {FileText, FolderIcon, Plus, Trash} from "lucide-angular"

import {IconDirective} from "@qualcomm-ui/angular/icon"
import {TreeModule} from "@qualcomm-ui/angular/tree"
import {provideIcons} from "@qualcomm-ui/angular-core/lucide"
import {useTreeContext} from "@qualcomm-ui/angular-core/tree"
import {createTreeCollection} from "@qualcomm-ui/core/tree"
import type {TreeCollection} from "@qualcomm-ui/utils/collection"

interface FileNode {
  id: string
  name: string
  nodes?: FileNode[]
}

@Component({
  imports: [TreeModule],
  providers: [provideIcons({Plus, Trash})],
  selector: "tree-node-actions",
  template: `
    <button
      aria-label="Remove node"
      icon="Trash"
      q-tree-node-action
      size="sm"
      (click)="onRemove()"
    ></button>
    @if (isBranch()) {
      <button
        aria-label="Add node"
        icon="Plus"
        q-tree-node-action
        size="sm"
        (click)="onAdd()"
      ></button>
    }
  `,
})
export class TreeNodeActions {
  readonly node = input.required<FileNode>()
  readonly indexPath = input.required<number[]>()
  readonly isBranch = input(false)

  readonly add = output<{indexPath: number[]; node: FileNode}>()
  readonly remove = output<{indexPath: number[]; node: FileNode}>()

  protected readonly treeContext = useTreeContext()

  onRemove() {
    this.remove.emit({indexPath: this.indexPath(), node: this.node()})
  }

  onAdd() {
    this.treeContext().expand([this.node().id])
    this.add.emit({indexPath: this.indexPath(), node: this.node()})
  }
}

const initialCollection = createTreeCollection<FileNode>({
  nodeChildren: "nodes",
  nodeText: "name",
  nodeValue: "id",
  rootNode: {
    id: "ROOT",
    name: "",
    nodes: [
      {
        id: "node_modules",
        name: "node_modules",
        nodes: [
          {
            id: "@qui",
            name: "@qui",
            nodes: [
              {
                id: "node_modules/@qualcomm-ui/core",
                name: "@qualcomm-ui/core",
              },
              {
                id: "node_modules/@qualcomm-ui/react",
                name: "@qualcomm-ui/react",
              },
              {
                id: "node_modules/@qualcomm-ui/react-core",
                name: "@qualcomm-ui/react-core",
              },
            ],
          },
          {
            id: "node_modules/@types",
            name: "@types",
            nodes: [
              {id: "node_modules/@types/react", name: "react"},
              {id: "node_modules/@types/react-dom", name: "react-dom"},
            ],
          },
        ],
      },
      {
        id: "src",
        name: "src",
        nodes: [
          {id: "src/app.tsx", name: "app.tsx"},
          {id: "src/index.ts", name: "index.ts"},
        ],
      },
      {id: "prettier.config.js", name: "prettier.config.js"},
      {id: "package.json", name: "package.json"},
      {id: "tsconfig.json", name: "tsconfig.json"},
    ],
  },
})

@Component({
  imports: [TreeModule, IconDirective, TreeNodeActions],
  providers: [provideIcons({FileText, FolderIcon, Plus, Trash})],
  selector: "tree-add-remove-demo",
  template: `
    <div class="w-full max-w-sm" q-tree-root [collection]="collection()">
      @for (
        node of collection().rootNode.nodes;
        let i = $index;
        track collection().getNodeValue(node)
      ) {
        <q-tree-nodes [indexPath]="[i]" [node]="node">
          <ng-template
            let-branch
            q-tree-branch-template
            [rootNode]="collection().rootNode"
          >
            <div q-tree-branch-node role="treeitem">
              <div q-tree-node-indicator></div>
              <div q-tree-branch-trigger></div>
              <svg q-tree-node-icon qIcon="FolderIcon"></svg>
              <span q-tree-node-text>
                {{ collection().stringifyNode(branch.node) }}
              </span>
              <tree-node-actions
                [indexPath]="branch.indexPath"
                [isBranch]="true"
                [node]="branch.node"
                (add)="addNode($event)"
                (remove)="removeNode($event)"
              />
            </div>
          </ng-template>

          <ng-template
            let-leaf
            q-tree-leaf-template
            [rootNode]="collection().rootNode"
          >
            <div q-tree-leaf-node>
              <div q-tree-node-indicator></div>
              <svg q-tree-node-icon qIcon="FileText"></svg>
              <span q-tree-node-text>
                {{ collection().stringifyNode(leaf.node) }}
              </span>
              <tree-node-actions
                [indexPath]="leaf.indexPath"
                [isBranch]="false"
                [node]="leaf.node"
                (remove)="removeNode($event)"
              />
            </div>
          </ng-template>
        </q-tree-nodes>
      }
    </div>
  `,
})
export class TreeAddRemoveDemo {
  readonly collection = signal<TreeCollection<FileNode>>(initialCollection)

  removeNode(event: {indexPath: number[]; node: FileNode}) {
    this.collection.update((c) => c.remove([event.indexPath]))
  }

  addNode(event: {indexPath: number[]; node: FileNode}) {
    const {indexPath, node} = event
    if (!this.collection().isBranchNode(node)) {
      return
    }

    const nodes = [
      {
        id: `untitled-${Date.now()}`,
        name: `untitled-${node.nodes?.length || 0}.tsx`,
      },
      ...(node.nodes || []),
    ]
    this.collection.update((c) => c.replace(indexPath, {...node, nodes}))
  }
}

API

q-tree-root

PropTypeDefault
The controlled checked node value
string[]
The tree collection data
The initial checked node value when rendered. Use when you don't need to control the checked node value.
string[]
The initial expanded node ids when rendered. Use when you don't need to control the expanded node value.
string[]
The initial focused node value when rendered. Use when you don't need to control the focused node value.
string
The initial selected node value when rendered. Use when you don't need to control the selected node value.
string[]
The document's text/writing direction.
'ltr' | 'rtl'
The controlled expanded node ids
string[]
Whether clicking on a branch should open it or not
boolean
true
The value of the focused node
string
A root node to correctly resolve the Document in custom environments. i.e., Iframes, Electron.
() =>
| Node
| ShadowRoot
| Document
HTML id attribute. If omitted, a unique identifier will be generated for accessibility.)
string
When true, the component will not be rendered in the DOM until it becomes visible or active.
boolean
false
Function to load children for a node asynchronously. When provided, branches will wait for this promise to resolve before expanding.
(details: {
indexPath: number[]
node: T
signal: AbortSignal
valuePath: string[]
}) => Promise<any[]>
The controlled selected node value
string[]
Whether the tree supports multiple selection
  • 'single': only one node can be selected
  • 'multiple': multiple nodes can be selected
| 'multiple'
| 'single'
'single'
Callback function that determines whether a node should be hidden.
InputSigna
The size of the tree and its elements. Governs properties like font size, item padding, and icon sizes.
'sm' | 'md'
'md'
Whether the tree supports typeahead search
boolean
true
When true, the component will be completely removed from the DOM when it becomes inactive or hidden, rather than just being hidden with CSS.
boolean
false
Called when the checked value changes
{
checkedNodes: Array<T>
checkedValue: string[]
}
Called when the tree is opened or closed
{
expandedNodes: Array<T>
expandedValue: string[]
focusedValue: string
}
Called when the focused node changes
{
focusedNode: T
focusedValue: string
}
Called when a node finishes loading children
{
collection: TreeCollection<T>
}
Called when loading children fails for one or more nodes
{
nodes: NodeWithError[]
}
Called when the selection changes
{
focusedValue: string
selectedNodes: Array<T>
selectedValue: string[]
}
Type
string[]
Description
The controlled checked node value
Description
The tree collection data
Type
string[]
Description
The initial checked node value when rendered. Use when you don't need to control the checked node value.
Type
string[]
Description
The initial expanded node ids when rendered. Use when you don't need to control the expanded node value.
Type
string
Description
The initial focused node value when rendered. Use when you don't need to control the focused node value.
Type
string[]
Description
The initial selected node value when rendered. Use when you don't need to control the selected node value.
Type
'ltr' | 'rtl'
Description
The document's text/writing direction.
Type
string[]
Description
The controlled expanded node ids
Type
boolean
Description
Whether clicking on a branch should open it or not
Type
string
Description
The value of the focused node
Type
() =>
| Node
| ShadowRoot
| Document
Description
A root node to correctly resolve the Document in custom environments. i.e., Iframes, Electron.
Type
string
Description
HTML id attribute. If omitted, a unique identifier will be generated for accessibility.)
Type
boolean
Description
When true, the component will not be rendered in the DOM until it becomes visible or active.
Type
(details: {
indexPath: number[]
node: T
signal: AbortSignal
valuePath: string[]
}) => Promise<any[]>
Description
Function to load children for a node asynchronously. When provided, branches will wait for this promise to resolve before expanding.
Type
string[]
Description
The controlled selected node value
Type
| 'multiple'
| 'single'
Description
Whether the tree supports multiple selection
  • 'single': only one node can be selected
  • 'multiple': multiple nodes can be selected
Type
InputSigna
Description
Callback function that determines whether a node should be hidden.
Type
'sm' | 'md'
Description
The size of the tree and its elements. Governs properties like font size, item padding, and icon sizes.
Type
boolean
Description
Whether the tree supports typeahead search
Type
boolean
Description
When true, the component will be completely removed from the DOM when it becomes inactive or hidden, rather than just being hidden with CSS.
Type
{
checkedNodes: Array<T>
checkedValue: string[]
}
Description
Called when the checked value changes
Type
{
expandedNodes: Array<T>
expandedValue: string[]
focusedValue: string
}
Description
Called when the tree is opened or closed
Type
{
focusedNode: T
focusedValue: string
}
Description
Called when the focused node changes
Type
{
collection: TreeCollection<T>
}
Description
Called when a node finishes loading children
Type
{
nodes: NodeWithError[]
}
Description
Called when loading children fails for one or more nodes
Type
{
focusedValue: string
selectedNodes: Array<T>
selectedValue: string[]
}
Description
Called when the selection changes

q-tree-nodes

PropType
The index path of the tree node
number[]
The tree node
T
TemplateRef<any>
TemplateRef<any>
Type
number[]
Description
The index path of the tree node
Type
T
Description
The tree node
Type
TemplateRef<any>
Type
TemplateRef<any>

TreeCollection

Note that the TreeCollection accepts a single generic type parameter, T, which is the object type of the node used in the collection.

Constructor

The constructor of the TreeCollection class accepts the following options:

PropTypeDefault
Property key for accessing a node's children.
keyof T
"nodes"
Function to determine the count of a node's children.
      (
      node: T,
      ) => number
      Property key or function to determine if a node is disabled. When a string key is provided, the value of node[key] determines the disabled state.
      | keyof T
      | ((node: T) => boolean)
      "disabled"
      
      Property key or function for getting a node's text. When a string key is provided, the value of node[key] is used.
      | keyof T
      | ((node: T) => string)
      "text"
      
      Property key or function for getting a node's value. When a string key is provided, the value of node[key] is used.
      | keyof T
      | ((node: T) => string)
      "value"
      
      The root node of the tree
      T
      Type
      keyof T
      Description
      Property key for accessing a node's children.
      Type
      (
      node: T,
      ) => number
      Description
      Function to determine the count of a node's children.
          Type
          | keyof T
          | ((node: T) => boolean)
          Description
          Property key or function to determine if a node is disabled. When a string key is provided, the value of node[key] determines the disabled state.
          Type
          | keyof T
          | ((node: T) => string)
          Description
          Property key or function for getting a node's text. When a string key is provided, the value of node[key] is used.
          Type
          | keyof T
          | ((node: T) => string)
          Description
          Property key or function for getting a node's value. When a string key is provided, the value of node[key] is used.
          Type
          T
          Description
          The root node of the tree
          PropType
          Gets the node at the specified index path.
          • indexPath:Array of indices representing the path to the node
            (
            indexPath: number[],
            ) => T
            Checks if a parent index path contains a child index path.
            • parentIndexPath:The parent path
            • valueIndexPath:The child path to check
              (
              parentIndexPath: number[],
              valueIndexPath: number[],
              ) => boolean
              Creates a new tree collection with the same options but different root node.
              • rootNode:The new root node for the copied collection
                (
                rootNode: T,
                ) => any
                Filters the tree keeping only nodes that match the predicate.
                • predicate:Function to test each node
                  (
                  predicate: (
                  node: T,
                  indexPath: number[],
                  ) => boolean,
                  ) => any
                  Finds the first node with the specified value.
                  • value:The value to search for
                  • rootNode:The root node to start searching from
                    (
                    value: string,
                    rootNode?: T,
                    ) => T
                    (
                    predicate: (
                    node: T,
                    indexPath: number[],
                    ) => boolean,
                    rootNode?: T,
                    ) => T
                    Finds all nodes with values matching the provided array.
                    • values:Array of values to search for
                    • rootNode:The root node to start searching from
                      (
                      values: string[],
                      rootNode?: T,
                      ) => Array<T>
                      Flattens the tree into an array with parent/child relationships.
                      • rootNode:The root node to start flattening from
                        (
                        rootNode?: T,
                        ) => Array<
                        T & {
                        _children: number[]
                        _index: number
                        _parent: number
                        }
                        >
                        Gets all branch node values with optional depth filtering.
                        • rootNode:The root node to start from
                        • opts:Options for skipping nodes and filtering by depth
                          (
                          rootNode?: T,
                          opts?: {
                          skip?: (args: {
                          indexPath: number[]
                          node: T
                          value: string
                          }) => boolean | void
                          } & {
                          depth?:
                          | number
                          | ((
                          nodeDepth: number,
                          ) => boolean)
                          },
                          ) => string[]
                          Gets the depth of a node with the specified value.
                          • value:The value to find the depth for
                            (
                            value: string,
                            ) => number
                            Gets all descendant nodes of the specified node.
                            • valueOrIndexPath:Either a node value or index path
                            • options:Options for controlling which descendants to include
                              (
                              valueOrIndexPath?:
                              | string
                              | number[],
                              options?: T & {
                              disabled?: boolean
                              id?: string
                              onUnregister?: (
                              index: number,
                              ) => void
                              requireContext?: boolean
                              },
                              ) => Array<T>
                              Gets all descendant values of the specified node.
                              • valueOrIndexPath:Either a node value or index path
                              • options:Options for controlling which descendants to include
                                (
                                valueOrIndexPath:
                                | string
                                | number[],
                                options?: T & {
                                disabled?: boolean
                                id?: string
                                onUnregister?: (
                                index: number,
                                ) => void
                                requireContext?: boolean
                                },
                                ) => string[]
                                Gets the first non-disabled node in the tree.
                                • rootNode:The root node to start searching from
                                  (
                                  rootNode?: T,
                                  ) => T
                                  Gets the index path for a node with the specified value.
                                  • value:The value to find the index path for
                                    (
                                    value: string,
                                    ) => number[]
                                    Gets the last non-disabled node in the tree.
                                    • rootNode:The root node to start searching from
                                    • opts:Options for skipping nodes during traversal
                                      (
                                      rootNode?: T,
                                      opts?: {
                                      skip?: (args: {
                                      indexPath: number[]
                                      node: T
                                      value: string
                                      }) => boolean | void
                                      },
                                      ) => T
                                      Gets the next node after the one with the specified value.
                                      • value:The value to find the next node from
                                      • opts:Options for skipping nodes during traversal
                                        (
                                        value: string,
                                        opts?: {
                                        skip?: (args: {
                                        indexPath: number[]
                                        node: T
                                        value: string
                                        }) => boolean | void
                                        },
                                        ) => T
                                        Gets the next non-disabled sibling of the node at the index path.
                                        • indexPath:Array of indices representing the path to the node
                                          (
                                          indexPath: number[],
                                          ) => T
                                          Returns all child nodes for this node. Uses options.nodeToChildren if provided, otherwise falls back to default behavior.
                                              (
                                              node: T,
                                              ) => Array<T>
                                              Gets the number of children for a node, supporting lazy loading scenarios. Uses options.nodeToChildrenCount if provided, otherwise falls back to default behavior.
                                              • node:The node to get children count for
                                                (
                                                node: T,
                                                ) => number
                                                Checks if a node is disabled. Uses options.isNodeDisabled if provided, otherwise falls back to default behavior.
                                                • node:The node to check
                                                  (
                                                  node: T,
                                                  ) => boolean
                                                  Gets the string value for a node. Uses options.nodeValue if provided, otherwise falls back to default behavior.
                                                  • node:The node to get the value from
                                                    (
                                                    node: T,
                                                    ) => string
                                                    Gets the parent node of the specified node.
                                                    • valueOrIndexPath:Either a node value or index path
                                                      (
                                                      valueOrIndexPath:
                                                      | string
                                                      | number[],
                                                      ) => T
                                                      Gets all parent nodes from root to the specified node.
                                                      • valueOrIndexPath:Either a node value or index path
                                                        (
                                                        valueOrIndexPath:
                                                        | string
                                                        | number[],
                                                        ) => Array<T>
                                                        Gets the previous node before the one with the specified value.
                                                        • value:The value to find the previous node from
                                                        • opts:Options for skipping nodes during traversal
                                                          (
                                                          value: string,
                                                          opts?: {
                                                          skip?: (args: {
                                                          indexPath: number[]
                                                          node: T
                                                          value: string
                                                          }) => boolean | void
                                                          },
                                                          ) => T
                                                          Gets the previous non-disabled sibling of the node at the index path.
                                                          • indexPath:Array of indices representing the path to the node
                                                            (
                                                            indexPath: number[],
                                                            ) => T
                                                            Gets all sibling nodes of the node at the index path.
                                                            • indexPath:Array of indices representing the path to the node
                                                              (
                                                              indexPath: number[],
                                                              ) => Array<T>
                                                              Gets the value of the node at the specified index path.
                                                              • indexPath:Array of indices representing the path to the node
                                                                (
                                                                indexPath: number[],
                                                                ) => string
                                                                Gets the path of values from root to the specified index path.
                                                                • indexPath:Array of indices representing the path to the node
                                                                  (
                                                                  indexPath: number[],
                                                                  ) => string[]
                                                                  Gets all values in the tree, excluding the root node.
                                                                  • rootNode:The root node to start from
                                                                    (
                                                                    rootNode?: T,
                                                                    ) => string[]
                                                                    Groups children of a parent node by a specified key.
                                                                    • parentIndexPath:Index path of the parent node whose children to group. Pass [] for root-level children.
                                                                    • groupBy:Function that determines the group key for each child node
                                                                    • sortGroups:Optional array of group keys defining order, or comparator function to sort the groups. By default, groups are sorted by first occurrence in the tree (insertion order)
                                                                      (
                                                                      parentIndexPath: IndexPath,
                                                                      groupBy: (
                                                                      node: T,
                                                                      index: number,
                                                                      ) => string,
                                                                      sortGroups?:
                                                                      | string[]
                                                                      | ((
                                                                      a: {
                                                                      items: Array<{
                                                                      indexPath: IndexPath
                                                                      node: T
                                                                      }>
                                                                      key: string
                                                                      },
                                                                      b: {
                                                                      items: Array<{
                                                                      indexPath: IndexPath
                                                                      node: T
                                                                      }>
                                                                      key: string
                                                                      },
                                                                      ) => number),
                                                                      ) => GroupedTreeNode<T>[]
                                                                      Inserts nodes after the node at the specified index path.
                                                                      • indexPath:Array of indices representing the insertion point
                                                                      • nodes:Array of nodes to insert
                                                                        (
                                                                        indexPath: number[],
                                                                        nodes: Array<T>,
                                                                        ) => any
                                                                        Inserts nodes before the node at the specified index path.
                                                                        • indexPath:Array of indices representing the insertion point
                                                                        • nodes:Array of nodes to insert
                                                                          (
                                                                          indexPath: number[],
                                                                          nodes: Array<T>,
                                                                          ) => any
                                                                          Checks if a node is a branch node (has children or can have children).
                                                                          • node:The node to check
                                                                            (
                                                                            node: T,
                                                                            ) => boolean
                                                                            Compares this tree collection with another for deep equality.
                                                                            • other:The other tree collection to compare with
                                                                              (
                                                                              other: TreeCollection<T>,
                                                                              ) => boolean
                                                                              Checks if a node is the root node.
                                                                              • node:The node to check
                                                                                (
                                                                                node: T,
                                                                                ) => boolean
                                                                                Checks if two nodes are the same by comparing their values.
                                                                                • node:First node to compare
                                                                                • other:Second node to compare
                                                                                  (
                                                                                  node: T,
                                                                                  other: T,
                                                                                  ) => boolean
                                                                                  Moves nodes from one location to another in the tree.
                                                                                  • fromIndexPaths:Array of index paths to move from
                                                                                  • toIndexPath:Index path to move to
                                                                                    (
                                                                                    fromIndexPaths: Array<
                                                                                    number[]
                                                                                    >,
                                                                                    toIndexPath: number[],
                                                                                    ) => any
                                                                                    Removes nodes at the specified index paths.
                                                                                    • indexPaths:Array of index paths to remove
                                                                                      (
                                                                                      indexPaths: Array<number[]>,
                                                                                      ) => any
                                                                                      Replaces the node at the specified index path.
                                                                                      • indexPath:Array of indices representing the path to the node
                                                                                      • node:The new node to replace with
                                                                                        (
                                                                                        indexPath: number[],
                                                                                        node: T,
                                                                                        ) => any
                                                                                        The root tree node.
                                                                                        T
                                                                                        Sorts values according to their tree order.
                                                                                        • values:Array of values to sort
                                                                                          (
                                                                                          values: string[],
                                                                                          ) => string[]
                                                                                          Converts a node value to its string representation.
                                                                                          • value:The value to stringify
                                                                                          (
                                                                                          value: string,
                                                                                          ) => string
                                                                                          Converts a node to its string representation. Uses options.nodeLabel if provided, otherwise falls back to default behavior: uses node.text, or node.value if node.text is not available.
                                                                                          • node:The node to stringify
                                                                                          (
                                                                                          T,
                                                                                          ) => string
                                                                                          Serializes the tree to a JSON-compatible array of values.
                                                                                              () => string[]
                                                                                              Visits all nodes in the tree with optional skip functionality.
                                                                                              • opts:Options for visiting nodes, including skip predicate
                                                                                                (opts: {
                                                                                                onEnter?: (
                                                                                                node: T,
                                                                                                indexPath: number[],
                                                                                                ) => void | 'skip' | 'stop'
                                                                                                onLeave?: (
                                                                                                node: T,
                                                                                                indexPath: number[],
                                                                                                ) => void | 'stop'
                                                                                                reuseIndexPath?: boolean
                                                                                                skip?: (args: {
                                                                                                indexPath: number[]
                                                                                                node: T
                                                                                                value: string
                                                                                                }) => boolean | void
                                                                                                }) => void
                                                                                                Type
                                                                                                (
                                                                                                indexPath: number[],
                                                                                                ) => T
                                                                                                Description
                                                                                                Gets the node at the specified index path.
                                                                                                • indexPath:Array of indices representing the path to the node
                                                                                                  Type
                                                                                                  (
                                                                                                  parentIndexPath: number[],
                                                                                                  valueIndexPath: number[],
                                                                                                  ) => boolean
                                                                                                  Description
                                                                                                  Checks if a parent index path contains a child index path.
                                                                                                  • parentIndexPath:The parent path
                                                                                                  • valueIndexPath:The child path to check
                                                                                                    Type
                                                                                                    (
                                                                                                    rootNode: T,
                                                                                                    ) => any
                                                                                                    Description
                                                                                                    Creates a new tree collection with the same options but different root node.
                                                                                                    • rootNode:The new root node for the copied collection
                                                                                                      Type
                                                                                                      (
                                                                                                      predicate: (
                                                                                                      node: T,
                                                                                                      indexPath: number[],
                                                                                                      ) => boolean,
                                                                                                      ) => any
                                                                                                      Description
                                                                                                      Filters the tree keeping only nodes that match the predicate.
                                                                                                      • predicate:Function to test each node
                                                                                                        Type
                                                                                                        (
                                                                                                        value: string,
                                                                                                        rootNode?: T,
                                                                                                        ) => T
                                                                                                        Description
                                                                                                        Finds the first node with the specified value.
                                                                                                        • value:The value to search for
                                                                                                        • rootNode:The root node to start searching from
                                                                                                          Type
                                                                                                          (
                                                                                                          predicate: (
                                                                                                          node: T,
                                                                                                          indexPath: number[],
                                                                                                          ) => boolean,
                                                                                                          rootNode?: T,
                                                                                                          ) => T
                                                                                                          Type
                                                                                                          (
                                                                                                          values: string[],
                                                                                                          rootNode?: T,
                                                                                                          ) => Array<T>
                                                                                                          Description
                                                                                                          Finds all nodes with values matching the provided array.
                                                                                                          • values:Array of values to search for
                                                                                                          • rootNode:The root node to start searching from
                                                                                                            Type
                                                                                                            (
                                                                                                            rootNode?: T,
                                                                                                            ) => Array<
                                                                                                            T & {
                                                                                                            _children: number[]
                                                                                                            _index: number
                                                                                                            _parent: number
                                                                                                            }
                                                                                                            >
                                                                                                            Description
                                                                                                            Flattens the tree into an array with parent/child relationships.
                                                                                                            • rootNode:The root node to start flattening from
                                                                                                              Type
                                                                                                              (
                                                                                                              rootNode?: T,
                                                                                                              opts?: {
                                                                                                              skip?: (args: {
                                                                                                              indexPath: number[]
                                                                                                              node: T
                                                                                                              value: string
                                                                                                              }) => boolean | void
                                                                                                              } & {
                                                                                                              depth?:
                                                                                                              | number
                                                                                                              | ((
                                                                                                              nodeDepth: number,
                                                                                                              ) => boolean)
                                                                                                              },
                                                                                                              ) => string[]
                                                                                                              Description
                                                                                                              Gets all branch node values with optional depth filtering.
                                                                                                              • rootNode:The root node to start from
                                                                                                              • opts:Options for skipping nodes and filtering by depth
                                                                                                                Type
                                                                                                                (
                                                                                                                value: string,
                                                                                                                ) => number
                                                                                                                Description
                                                                                                                Gets the depth of a node with the specified value.
                                                                                                                • value:The value to find the depth for
                                                                                                                  Type
                                                                                                                  (
                                                                                                                  valueOrIndexPath?:
                                                                                                                  | string
                                                                                                                  | number[],
                                                                                                                  options?: T & {
                                                                                                                  disabled?: boolean
                                                                                                                  id?: string
                                                                                                                  onUnregister?: (
                                                                                                                  index: number,
                                                                                                                  ) => void
                                                                                                                  requireContext?: boolean
                                                                                                                  },
                                                                                                                  ) => Array<T>
                                                                                                                  Description
                                                                                                                  Gets all descendant nodes of the specified node.
                                                                                                                  • valueOrIndexPath:Either a node value or index path
                                                                                                                  • options:Options for controlling which descendants to include
                                                                                                                    Type
                                                                                                                    (
                                                                                                                    valueOrIndexPath:
                                                                                                                    | string
                                                                                                                    | number[],
                                                                                                                    options?: T & {
                                                                                                                    disabled?: boolean
                                                                                                                    id?: string
                                                                                                                    onUnregister?: (
                                                                                                                    index: number,
                                                                                                                    ) => void
                                                                                                                    requireContext?: boolean
                                                                                                                    },
                                                                                                                    ) => string[]
                                                                                                                    Description
                                                                                                                    Gets all descendant values of the specified node.
                                                                                                                    • valueOrIndexPath:Either a node value or index path
                                                                                                                    • options:Options for controlling which descendants to include
                                                                                                                      Type
                                                                                                                      (
                                                                                                                      rootNode?: T,
                                                                                                                      ) => T
                                                                                                                      Description
                                                                                                                      Gets the first non-disabled node in the tree.
                                                                                                                      • rootNode:The root node to start searching from
                                                                                                                        Type
                                                                                                                        (
                                                                                                                        value: string,
                                                                                                                        ) => number[]
                                                                                                                        Description
                                                                                                                        Gets the index path for a node with the specified value.
                                                                                                                        • value:The value to find the index path for
                                                                                                                          Type
                                                                                                                          (
                                                                                                                          rootNode?: T,
                                                                                                                          opts?: {
                                                                                                                          skip?: (args: {
                                                                                                                          indexPath: number[]
                                                                                                                          node: T
                                                                                                                          value: string
                                                                                                                          }) => boolean | void
                                                                                                                          },
                                                                                                                          ) => T
                                                                                                                          Description
                                                                                                                          Gets the last non-disabled node in the tree.
                                                                                                                          • rootNode:The root node to start searching from
                                                                                                                          • opts:Options for skipping nodes during traversal
                                                                                                                            Type
                                                                                                                            (
                                                                                                                            value: string,
                                                                                                                            opts?: {
                                                                                                                            skip?: (args: {
                                                                                                                            indexPath: number[]
                                                                                                                            node: T
                                                                                                                            value: string
                                                                                                                            }) => boolean | void
                                                                                                                            },
                                                                                                                            ) => T
                                                                                                                            Description
                                                                                                                            Gets the next node after the one with the specified value.
                                                                                                                            • value:The value to find the next node from
                                                                                                                            • opts:Options for skipping nodes during traversal
                                                                                                                              Type
                                                                                                                              (
                                                                                                                              indexPath: number[],
                                                                                                                              ) => T
                                                                                                                              Description
                                                                                                                              Gets the next non-disabled sibling of the node at the index path.
                                                                                                                              • indexPath:Array of indices representing the path to the node
                                                                                                                                Type
                                                                                                                                (
                                                                                                                                node: T,
                                                                                                                                ) => Array<T>
                                                                                                                                Description
                                                                                                                                Returns all child nodes for this node. Uses options.nodeToChildren if provided, otherwise falls back to default behavior.
                                                                                                                                    Type
                                                                                                                                    (
                                                                                                                                    node: T,
                                                                                                                                    ) => number
                                                                                                                                    Description
                                                                                                                                    Gets the number of children for a node, supporting lazy loading scenarios. Uses options.nodeToChildrenCount if provided, otherwise falls back to default behavior.
                                                                                                                                    • node:The node to get children count for
                                                                                                                                      Type
                                                                                                                                      (
                                                                                                                                      node: T,
                                                                                                                                      ) => boolean
                                                                                                                                      Description
                                                                                                                                      Checks if a node is disabled. Uses options.isNodeDisabled if provided, otherwise falls back to default behavior.
                                                                                                                                      • node:The node to check
                                                                                                                                        Type
                                                                                                                                        (
                                                                                                                                        node: T,
                                                                                                                                        ) => string
                                                                                                                                        Description
                                                                                                                                        Gets the string value for a node. Uses options.nodeValue if provided, otherwise falls back to default behavior.
                                                                                                                                        • node:The node to get the value from
                                                                                                                                          Type
                                                                                                                                          (
                                                                                                                                          valueOrIndexPath:
                                                                                                                                          | string
                                                                                                                                          | number[],
                                                                                                                                          ) => T
                                                                                                                                          Description
                                                                                                                                          Gets the parent node of the specified node.
                                                                                                                                          • valueOrIndexPath:Either a node value or index path
                                                                                                                                            Type
                                                                                                                                            (
                                                                                                                                            valueOrIndexPath:
                                                                                                                                            | string
                                                                                                                                            | number[],
                                                                                                                                            ) => Array<T>
                                                                                                                                            Description
                                                                                                                                            Gets all parent nodes from root to the specified node.
                                                                                                                                            • valueOrIndexPath:Either a node value or index path
                                                                                                                                              Type
                                                                                                                                              (
                                                                                                                                              value: string,
                                                                                                                                              opts?: {
                                                                                                                                              skip?: (args: {
                                                                                                                                              indexPath: number[]
                                                                                                                                              node: T
                                                                                                                                              value: string
                                                                                                                                              }) => boolean | void
                                                                                                                                              },
                                                                                                                                              ) => T
                                                                                                                                              Description
                                                                                                                                              Gets the previous node before the one with the specified value.
                                                                                                                                              • value:The value to find the previous node from
                                                                                                                                              • opts:Options for skipping nodes during traversal
                                                                                                                                                Type
                                                                                                                                                (
                                                                                                                                                indexPath: number[],
                                                                                                                                                ) => T
                                                                                                                                                Description
                                                                                                                                                Gets the previous non-disabled sibling of the node at the index path.
                                                                                                                                                • indexPath:Array of indices representing the path to the node
                                                                                                                                                  Type
                                                                                                                                                  (
                                                                                                                                                  indexPath: number[],
                                                                                                                                                  ) => Array<T>
                                                                                                                                                  Description
                                                                                                                                                  Gets all sibling nodes of the node at the index path.
                                                                                                                                                  • indexPath:Array of indices representing the path to the node
                                                                                                                                                    Type
                                                                                                                                                    (
                                                                                                                                                    indexPath: number[],
                                                                                                                                                    ) => string
                                                                                                                                                    Description
                                                                                                                                                    Gets the value of the node at the specified index path.
                                                                                                                                                    • indexPath:Array of indices representing the path to the node
                                                                                                                                                      Type
                                                                                                                                                      (
                                                                                                                                                      indexPath: number[],
                                                                                                                                                      ) => string[]
                                                                                                                                                      Description
                                                                                                                                                      Gets the path of values from root to the specified index path.
                                                                                                                                                      • indexPath:Array of indices representing the path to the node
                                                                                                                                                        Type
                                                                                                                                                        (
                                                                                                                                                        rootNode?: T,
                                                                                                                                                        ) => string[]
                                                                                                                                                        Description
                                                                                                                                                        Gets all values in the tree, excluding the root node.
                                                                                                                                                        • rootNode:The root node to start from
                                                                                                                                                          Type
                                                                                                                                                          (
                                                                                                                                                          parentIndexPath: IndexPath,
                                                                                                                                                          groupBy: (
                                                                                                                                                          node: T,
                                                                                                                                                          index: number,
                                                                                                                                                          ) => string,
                                                                                                                                                          sortGroups?:
                                                                                                                                                          | string[]
                                                                                                                                                          | ((
                                                                                                                                                          a: {
                                                                                                                                                          items: Array<{
                                                                                                                                                          indexPath: IndexPath
                                                                                                                                                          node: T
                                                                                                                                                          }>
                                                                                                                                                          key: string
                                                                                                                                                          },
                                                                                                                                                          b: {
                                                                                                                                                          items: Array<{
                                                                                                                                                          indexPath: IndexPath
                                                                                                                                                          node: T
                                                                                                                                                          }>
                                                                                                                                                          key: string
                                                                                                                                                          },
                                                                                                                                                          ) => number),
                                                                                                                                                          ) => GroupedTreeNode<T>[]
                                                                                                                                                          Description
                                                                                                                                                          Groups children of a parent node by a specified key.
                                                                                                                                                          • parentIndexPath:Index path of the parent node whose children to group. Pass [] for root-level children.
                                                                                                                                                          • groupBy:Function that determines the group key for each child node
                                                                                                                                                          • sortGroups:Optional array of group keys defining order, or comparator function to sort the groups. By default, groups are sorted by first occurrence in the tree (insertion order)
                                                                                                                                                            Type
                                                                                                                                                            (
                                                                                                                                                            indexPath: number[],
                                                                                                                                                            nodes: Array<T>,
                                                                                                                                                            ) => any
                                                                                                                                                            Description
                                                                                                                                                            Inserts nodes after the node at the specified index path.
                                                                                                                                                            • indexPath:Array of indices representing the insertion point
                                                                                                                                                            • nodes:Array of nodes to insert
                                                                                                                                                              Type
                                                                                                                                                              (
                                                                                                                                                              indexPath: number[],
                                                                                                                                                              nodes: Array<T>,
                                                                                                                                                              ) => any
                                                                                                                                                              Description
                                                                                                                                                              Inserts nodes before the node at the specified index path.
                                                                                                                                                              • indexPath:Array of indices representing the insertion point
                                                                                                                                                              • nodes:Array of nodes to insert
                                                                                                                                                                Type
                                                                                                                                                                (
                                                                                                                                                                node: T,
                                                                                                                                                                ) => boolean
                                                                                                                                                                Description
                                                                                                                                                                Checks if a node is a branch node (has children or can have children).
                                                                                                                                                                • node:The node to check
                                                                                                                                                                  Type
                                                                                                                                                                  (
                                                                                                                                                                  other: TreeCollection<T>,
                                                                                                                                                                  ) => boolean
                                                                                                                                                                  Description
                                                                                                                                                                  Compares this tree collection with another for deep equality.
                                                                                                                                                                  • other:The other tree collection to compare with
                                                                                                                                                                    Type
                                                                                                                                                                    (
                                                                                                                                                                    node: T,
                                                                                                                                                                    ) => boolean
                                                                                                                                                                    Description
                                                                                                                                                                    Checks if a node is the root node.
                                                                                                                                                                    • node:The node to check
                                                                                                                                                                      Type
                                                                                                                                                                      (
                                                                                                                                                                      node: T,
                                                                                                                                                                      other: T,
                                                                                                                                                                      ) => boolean
                                                                                                                                                                      Description
                                                                                                                                                                      Checks if two nodes are the same by comparing their values.
                                                                                                                                                                      • node:First node to compare
                                                                                                                                                                      • other:Second node to compare
                                                                                                                                                                        Type
                                                                                                                                                                        (
                                                                                                                                                                        fromIndexPaths: Array<
                                                                                                                                                                        number[]
                                                                                                                                                                        >,
                                                                                                                                                                        toIndexPath: number[],
                                                                                                                                                                        ) => any
                                                                                                                                                                        Description
                                                                                                                                                                        Moves nodes from one location to another in the tree.
                                                                                                                                                                        • fromIndexPaths:Array of index paths to move from
                                                                                                                                                                        • toIndexPath:Index path to move to
                                                                                                                                                                          Type
                                                                                                                                                                          (
                                                                                                                                                                          indexPaths: Array<number[]>,
                                                                                                                                                                          ) => any
                                                                                                                                                                          Description
                                                                                                                                                                          Removes nodes at the specified index paths.
                                                                                                                                                                          • indexPaths:Array of index paths to remove
                                                                                                                                                                            Type
                                                                                                                                                                            (
                                                                                                                                                                            indexPath: number[],
                                                                                                                                                                            node: T,
                                                                                                                                                                            ) => any
                                                                                                                                                                            Description
                                                                                                                                                                            Replaces the node at the specified index path.
                                                                                                                                                                            • indexPath:Array of indices representing the path to the node
                                                                                                                                                                            • node:The new node to replace with
                                                                                                                                                                              Type
                                                                                                                                                                              T
                                                                                                                                                                              Description
                                                                                                                                                                              The root tree node.
                                                                                                                                                                              Type
                                                                                                                                                                              (
                                                                                                                                                                              values: string[],
                                                                                                                                                                              ) => string[]
                                                                                                                                                                              Description
                                                                                                                                                                              Sorts values according to their tree order.
                                                                                                                                                                              • values:Array of values to sort
                                                                                                                                                                                Type
                                                                                                                                                                                (
                                                                                                                                                                                value: string,
                                                                                                                                                                                ) => string
                                                                                                                                                                                Description
                                                                                                                                                                                Converts a node value to its string representation.
                                                                                                                                                                                • value:The value to stringify
                                                                                                                                                                                Type
                                                                                                                                                                                (
                                                                                                                                                                                T,
                                                                                                                                                                                ) => string
                                                                                                                                                                                Description
                                                                                                                                                                                Converts a node to its string representation. Uses options.nodeLabel if provided, otherwise falls back to default behavior: uses node.text, or node.value if node.text is not available.
                                                                                                                                                                                • node:The node to stringify
                                                                                                                                                                                Type
                                                                                                                                                                                () => string[]
                                                                                                                                                                                Description
                                                                                                                                                                                Serializes the tree to a JSON-compatible array of values.
                                                                                                                                                                                    Type
                                                                                                                                                                                    (opts: {
                                                                                                                                                                                    onEnter?: (
                                                                                                                                                                                    node: T,
                                                                                                                                                                                    indexPath: number[],
                                                                                                                                                                                    ) => void | 'skip' | 'stop'
                                                                                                                                                                                    onLeave?: (
                                                                                                                                                                                    node: T,
                                                                                                                                                                                    indexPath: number[],
                                                                                                                                                                                    ) => void | 'stop'
                                                                                                                                                                                    reuseIndexPath?: boolean
                                                                                                                                                                                    skip?: (args: {
                                                                                                                                                                                    indexPath: number[]
                                                                                                                                                                                    node: T
                                                                                                                                                                                    value: string
                                                                                                                                                                                    }) => boolean | void
                                                                                                                                                                                    }) => void
                                                                                                                                                                                    Description
                                                                                                                                                                                    Visits all nodes in the tree with optional skip functionality.
                                                                                                                                                                                    • opts:Options for visiting nodes, including skip predicate

                                                                                                                                                                                      Element API

                                                                                                                                                                                      q-tree-label

                                                                                                                                                                                      PropType
                                                                                                                                                                                      id attribute. If omitted, a unique identifier will be generated for accessibility.
                                                                                                                                                                                      string
                                                                                                                                                                                      Type
                                                                                                                                                                                      string
                                                                                                                                                                                      Description
                                                                                                                                                                                      id attribute. If omitted, a unique identifier will be generated for accessibility.

                                                                                                                                                                                      q-tree-branch

                                                                                                                                                                                      q-tree-branch-node

                                                                                                                                                                                      q-tree-branch-trigger

                                                                                                                                                                                      PropTypeDefault
                                                                                                                                                                                      | LucideIconData
                                                                                                                                                                                      | string
                                                                                                                                                                                      ChevronRight
                                                                                                                                                                                      
                                                                                                                                                                                      Type
                                                                                                                                                                                      | LucideIconData
                                                                                                                                                                                      | string
                                                                                                                                                                                      Description

                                                                                                                                                                                      q-tree-branch-content

                                                                                                                                                                                      PropType
                                                                                                                                                                                      HTML id attribute. If omitted, a unique identifier will be generated for accessibility.)
                                                                                                                                                                                      string
                                                                                                                                                                                      Type
                                                                                                                                                                                      string
                                                                                                                                                                                      Description
                                                                                                                                                                                      HTML id attribute. If omitted, a unique identifier will be generated for accessibility.)

                                                                                                                                                                                      q-tree-branch-indent-guide

                                                                                                                                                                                      q-tree-leaf-node

                                                                                                                                                                                      q-tree-node-checkbox

                                                                                                                                                                                      q-tree-node-action

                                                                                                                                                                                      PropTypeDefault
                                                                                                                                                                                      Lucide icon to display inside the button.
                                                                                                                                                                                      | LucideIconData
                                                                                                                                                                                      | string
                                                                                                                                                                                      The size of the button and its icon.
                                                                                                                                                                                      | 'sm'
                                                                                                                                                                                      | 'md'
                                                                                                                                                                                      | 'lg'
                                                                                                                                                                                      'md'
                                                                                                                                                                                      
                                                                                                                                                                                      Type
                                                                                                                                                                                      | LucideIconData
                                                                                                                                                                                      | string
                                                                                                                                                                                      Description
                                                                                                                                                                                      Lucide icon to display inside the button.
                                                                                                                                                                                      Type
                                                                                                                                                                                      | 'sm'
                                                                                                                                                                                      | 'md'
                                                                                                                                                                                      | 'lg'
                                                                                                                                                                                      Description
                                                                                                                                                                                      The size of the button and its icon.

                                                                                                                                                                                      q-tree-node-indicator

                                                                                                                                                                                      q-tree-node-icon

                                                                                                                                                                                      PropType
                                                                                                                                                                                      | LucideIconData
                                                                                                                                                                                      | string
                                                                                                                                                                                      Type
                                                                                                                                                                                      | LucideIconData
                                                                                                                                                                                      | string

                                                                                                                                                                                      q-tree-node-text

                                                                                                                                                                                      Template Directives

                                                                                                                                                                                      q-tree-branch-template

                                                                                                                                                                                      Structural directive that defines the template used to render leaf nodes in a tree. Apply this to an ng-template to customize how branch nodes (nodes with children) are displayed. Note that this template will only customize the content of the node. The parent <q-tree-nodes> component renders the branch children internally.
                                                                                                                                                                                      PropType
                                                                                                                                                                                      The root node of the tree. Used for type narrowing of the template guard. Learn more
                                                                                                                                                                                      T
                                                                                                                                                                                      Type
                                                                                                                                                                                      T
                                                                                                                                                                                      Description
                                                                                                                                                                                      The root node of the tree. Used for type narrowing of the template guard. Learn more

                                                                                                                                                                                      q-tree-leaf-template

                                                                                                                                                                                      Structural directive that defines the template used to render leaf nodes in a tree. Apply this to an ng-template to customize how leaf nodes (nodes without children) are displayed.
                                                                                                                                                                                      PropType
                                                                                                                                                                                      The root node of the tree. Used for type narrowing of the template guard. Learn more
                                                                                                                                                                                      T
                                                                                                                                                                                      Type
                                                                                                                                                                                      T
                                                                                                                                                                                      Description
                                                                                                                                                                                      The root node of the tree. Used for type narrowing of the template guard. Learn more

                                                                                                                                                                                      Use this directive on an ng-template to customize the rendering of leaf nodes within q-tree-nodes.