A dropdown that lets users pick node(s) from a (possibly huge, lazily-loaded) tree. Data is supplied through a TreeSelectProvider — either an InMemoryTreeSelectProvider for static trees or a custom provider that pages a backend. <bs-tree-select> is a ControlValueAccessor, so it works with [(ngModel)] and formControlName. Keyboard: ArrowDown opens the panel and moves into the tree, arrows walk it, Enter/Space pick or toggle a node, Escape closes.
It has no shadow root. Anything you render into it — row templates, node templates, cell renderers — stays in the document, so your app's stylesheet, your own component styles and Bootstrap's utility classes reach it normally.
Its own CSS is scoped at build time onto a data-mps attribute, the same device Angular uses for _ngcontent, so it cannot leak out onto your markup.
The trade-off runs the other way: page CSS now reaches this component's internals, exactly as emulated encapsulation behaves everywhere else. ::part() and ::slotted() no longer address it — use ordinary CSS selectors instead.
Backed by an HTTP provider that calls /api/treeItems, /api/treeItems/{id}/children and /api/treeItems/search. Roots and children load lazily; typing queries the server. (Requires the demo backend running.)
<bs-form>
<bs-tree-select
[provider]="httpProvider"
placeholder="Search the org tree…"
[(value)]="singleValue">
</bs-tree-select>
</bs-form>
import { inject, Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { firstValueFrom } from 'rxjs';
import {
NodePage, NodeRequest, TreeNode, TreeSelectProvider,
} from '@mintplayer/ng-bootstrap/tree-select';
@Injectable({ providedIn: 'root' })
export class TreeSelectHttpProvider implements TreeSelectProvider {
private readonly http = inject(HttpClient);
private readonly baseUrl = '/api/treeItems';
private readonly perPage = 50;
loadRoots = (req: NodeRequest) => this.fetch(this.baseUrl, req);
loadChildren = (parentId: string, req: NodeRequest) =>
this.fetch(`${this.baseUrl}/${parentId}/children`, req);
search = (query: string, req: NodeRequest) =>
this.fetch(`${this.baseUrl}/search`, req, query);
private async fetch(url: string, req: NodeRequest, query?: string): Promise<NodePage> {
const page = Math.floor((req.offset ?? 0) / this.perPage) + 1;
let params = new HttpParams()
.set('page', String(page)).set('perPage', String(this.perPage));
if (query !== undefined) params = params.set('q', query);
const r = await firstValueFrom(this.http.get<any>(url, { params }));
return {
nodes: r.items.map((d: any): TreeNode => ({
id: String(d.id), label: d.name, lazy: d.childCount > 0, meta: { code: d.code },
})),
hasMore: r.page * r.pageSize < r.totalCount,
};
}
}
mode="multiple" renders each selected node as a removable chip. This example uses an in-memory provider — no backend required.
<bs-form>
<bs-tree-select
mode="multiple"
[provider]="memoryProvider"
placeholder="Pick a few…"
[(value)]="multipleValue">
</bs-tree-select>
</bs-form>
import { InMemoryTreeSelectProvider, type TreeNode } from '@mintplayer/ng-bootstrap/tree-select';
const SAMPLE_TREE: TreeNode[] = [
{
id: 'fruit', label: 'Fruit', children: [
{ id: 'apple', label: 'Apple' },
{ id: 'banana', label: 'Banana' },
{ id: 'citrus', label: 'Citrus', children: [
{ id: 'orange', label: 'Orange' },
{ id: 'lemon', label: 'Lemon' },
] },
],
},
{ id: 'vegetables', label: 'Vegetables', children: [
{ id: 'carrot', label: 'Carrot' },
{ id: 'potato', label: 'Potato' },
] },
];
memoryProvider = new InMemoryTreeSelectProvider(SAMPLE_TREE, { pageSize: 50 });
multipleValue = signal<TreeNode[]>([]);
mode="checkbox" with [cascadeSelect]="true" shows a checkbox per node and cascades selection down to descendants (and reflects indeterminate parents).
<bs-form>
<bs-tree-select
mode="checkbox"
[cascadeSelect]="true"
[provider]="memoryProvider"
placeholder="Select branches…"
[(value)]="checkboxValue">
</bs-tree-select>
</bs-form>
variant="button" renders the trigger as a button with the search box inside the panel. [showClear]="true" adds a clear affordance once something is selected.
<bs-form>
<bs-tree-select
variant="button"
[showClear]="true"
[provider]="memoryProvider"
placeholder="Choose one"
[(value)]="buttonValue">
</bs-tree-select>
</bs-form>
Template-driven [(ngModel)] and reactive [formControl] both bind through the component's ControlValueAccessor: the value, the disabled state, and touched when focus leaves.
[][]
<!-- template-driven (FormsModule) -->
<bs-form>
<bs-tree-select mode="multiple" [provider]="memoryProvider" placeholder="Pick a few…" [(ngModel)]="value"></bs-tree-select>
</bs-form>
<!-- reactive (ReactiveFormsModule): control = new FormControl(...) -->
<bs-form>
<bs-tree-select mode="multiple" [provider]="memoryProvider" placeholder="Pick a few…" [formControl]="control"></bs-tree-select>
</bs-form>