Tree Select
Select from a hierarchy with parent/child checkboxes — leaf-based, searchable, in React (@bpdm/ui) and Angular (@bpdm/ng).
The Tree Select picks options from a hierarchy. Toggling a parent selects
all its children; selection is leaf-based — value is the array of selected
leaf values. Nodes are data-driven via options (each node can have children).
Usage
import { TreeSelect } from '@bpdm/ui/tree-select';
const TREE = [
{
value: 'frontend',
label: 'Frontend',
children: [
{ value: 'react', label: 'React' },
{ value: 'angular', label: 'Angular' },
{ value: 'vue', label: 'Vue' },
],
},
{
value: 'backend',
label: 'Backend',
children: [
{ value: 'node', label: 'Node.js' },
{ value: 'go', label: 'Go' },
{ value: 'rust', label: 'Rust' },
],
},
];
export function TreeSelectUsage() {
return <TreeSelect options={TREE} defaultValue={['react', 'vue']} placeholder="Select technologies" />;
}Searchable
Set searchable to filter the tree — matches stay visible with their ancestors
expanded.
import { TreeSelect } from '@bpdm/ui/tree-select';
const TREE = [
{ value: 'frontend', label: 'Frontend', children: [
{ value: 'react', label: 'React' },
{ value: 'vue', label: 'Vue' },
] },
{ value: 'backend', label: 'Backend', children: [
{ value: 'node', label: 'Node.js' },
{ value: 'go', label: 'Go' },
] },
];
export function SearchableTree() {
return <TreeSelect options={TREE} searchable placeholder="Search technologies" />;
}Count display
Like Multi-select, set maxDisplay={0} to show a compact "N selected" count
instead of chips.
import { TreeSelect } from '@bpdm/ui/tree-select';
const TREE = [
{ value: 'frontend', label: 'Frontend', children: [
{ value: 'react', label: 'React' },
{ value: 'vue', label: 'Vue' },
] },
{ value: 'backend', label: 'Backend', children: [
{ value: 'node', label: 'Node.js' },
{ value: 'go', label: 'Go' },
] },
];
export function CountDisplay() {
return <TreeSelect options={TREE} maxDisplay={0} defaultValue={['react', 'vue', 'node']} />;
}States
import { TreeSelect } from '@bpdm/ui/tree-select';
const TREE = [
{ value: 'frontend', label: 'Frontend', children: [{ value: 'react', label: 'React' }] },
{ value: 'backend', label: 'Backend', children: [{ value: 'node', label: 'Node.js' }] },
];
export function States() {
return (
<div className="flex flex-col gap-3">
<TreeSelect options={TREE} placeholder="Default" />
<TreeSelect options={TREE} aria-invalid placeholder="Invalid" />
<TreeSelect options={TREE} disabled placeholder="Disabled" />
</div>
);
}Per-slot styling
className (or Angular class) styles the trigger as a whole. To restyle individual
parts without reaching into the internal data-bpdm-slot elements from CSS, pass a
classNames object — one key per slot: trigger, chip, clear, content, selectAll,
search, empty, group, tree and item. Each entry merges with the component's own
classes, so you override only what you name.
import { TreeSelect } from '@bpdm/ui/tree-select';
const TREE = [
{
value: 'frontend',
label: 'Frontend',
children: [
{ value: 'react', label: 'React' },
{ value: 'angular', label: 'Angular' },
{ value: 'vue', label: 'Vue' },
],
},
{
value: 'backend',
label: 'Backend',
children: [
{ value: 'node', label: 'Node.js' },
{ value: 'go', label: 'Go' },
{ value: 'rust', label: 'Rust' },
],
},
];
export function BrandedTreeSelect() {
return (
<TreeSelect
searchable
options={TREE}
defaultValue={['react', 'vue']}
placeholder="Select technologies"
classNames={{
trigger: 'rounded-xl border-2',
chip: 'rounded-full uppercase tracking-wide',
selectAll: 'uppercase tracking-wide text-primary',
search: 'bg-muted',
tree: 'rounded-lg bg-muted/40',
item: 'rounded-md',
}}
/>
);
}API
| Prop | Type | Default | Description |
|---|---|---|---|
options | TreeNode[] ({ value, label, disabled?, children? }) | — | Required. The hierarchy. |
value / defaultValue | string[] | — | Selected leaf values (controlled / uncontrolled). |
onValueChange | (value: string[]) => void | — | React — fires on change. Angular uses [(value)] or binds via formControlName / [(ngModel)] (see Forms). |
placeholder | string | Select… | Text when nothing is selected. |
maxDisplay | number | 3 | Chips before "+N"; 0 → "N selected". |
selectAll | boolean | true | Show a "Select all" row. |
searchable | boolean | false | Filter the tree. |
searchPlaceholder | string | Search… | Filter placeholder. |
emptyText | string | No results. | Shown when nothing matches. |
size | sm | md | lg | md | Trigger height / text size. |
disabled | boolean | false | Disable the control. |
aria-invalid | boolean | — | Error state. |
id | string | — | Trigger id (for <label> association / testing). |
aria-label / aria-describedby | string | — | Accessible name / description for the trigger + tree. |
messages | { expand, collapse, selectAll, clearAll, selected(count) } | English | Override the built-in labels + count text for i18n. |
classNames | TreeSelectClassNames | — | Per-slot class overrides: { trigger, chip, clear, content, selectAll, search, empty, group, tree, item }. Each merges with the component's own classes. |
TreeSelectClassNames: { trigger, chip, clear, content, selectAll, search, empty, group, tree, item }.
Forms
Fully controlled through value (the array of selected leaf values) + onValueChange, so it
drops into any form library. With react-hook-form, wrap it in a <Controller>:
<Controller
name="teams"
control={control}
render={({ field }) => (
<TreeSelect options={tree} value={field.value} onValueChange={field.onChange} />
)}
/>Accessibility
- Built on the WAI-ARIA tree pattern: the panel is
role="tree"(aria-multiselectable), each node is arole="treeitem"carryingaria-level,aria-expanded(branches), and its chosen state as botharia-selectedandaria-checked(true/false/mixed— a parent ismixedwhen only some descendants are chosen); child nodes sit in a nestedrole="group". The trigger isrole="combobox"witharia-haspopup="tree"andaria-controls. Both state attributes are set so more screen readers surface the state — some readaria-selected, othersaria-checked. - The caret and the checkbox glyph are decorative (
aria-hidden) — state is conveyed byaria-expanded/aria-checked, never a glyph alone. Select all is a tri-staterole="checkbox". - Fully operable by keyboard. The tree is a single tab stop and tracks the active node with
aria-activedescendant: Up / Down move between visible treeitems, Right expands a collapsed branch then steps into it, Left collapses an expanded branch or moves to the parent (both flip underdir="rtl"), Home / End jump to the first / last visible node, Enter / Space toggle selection, type-ahead jumps to the next matching label, and Esc closes. Give the field a name via<label>(id) oraria-label, and setaria-invalidon error.
Internationalization
- All built-in copy is translatable:
placeholder/searchPlaceholder/emptyTextare props, and themessagesprop overrides the branchexpand/collapselabels,selectAll,clearAll, and theselected(count)count text. Node labels are your data. - RTL-safe: node indentation uses
padding-inline-start, the caret mirrors underdir="rtl", and labels use logical alignment (text-start), so the whole tree flips correctly right-to-left. See the Internationalization guide.