TreeSelect
A selector combining a dropdown trigger with a tree panel: single selection returns string, multiple selection (checkboxes) returns string[].
Basic usage
Single select
Current value: (not selected)
Multiple select
Current value: (empty)
import { useState } from 'react'
import { LhTreeSelect } from '@lh-ui/react'
import type { LhTreeNode } from '@lh-ui/react'
const data: LhTreeNode[] = [
{
key: 'frontend',
label: 'Frontend',
children: [
{ key: 'vue', label: 'Vue' },
{ key: 'react', label: 'React' },
],
},
{
key: 'backend',
label: 'Backend',
children: [{ key: 'node', label: 'Node' }],
},
]
export default function Demo() {
const [value, setValue] = useState<string>()
return (
<LhTreeSelect
data={data}
value={value}
placeholder="Select a tech stack"
onChange={(next) => setValue(next as string | undefined)}
/>
)
}
TreeSelect Props
| Prop | Description | Type | Options | Default |
|---|---|---|---|---|
| data | Tree data | LhTreeNode[] | — | [] |
| value | Controlled value (single string / multiple string[]) | string | string[] | — | — |
| defaultValue | Uncontrolled default value | string | string[] | — | — |
| multiple | Multiple selection (shows checkboxes; value is the array of checked keys) | boolean | — | false |
| disabled | Whether to disable | boolean | — | false |
| placeholder | Placeholder | string | — | Locale pack fallback |
| teleported | Whether the panel mounts to body (false renders in place) | boolean | — | true |
| sx | Shorthand layout props | SxProps | — | — |
LhTreeNode
| Prop | Description | Type |
|---|---|---|
| key | Unique key | string |
| label | Display text | string |
| children | Child nodes | LhTreeNode[] |
| disabled | Disable this node (disabled subtrees are skipped in cascading checks) | boolean |
| isLeaf | Leaf marker (inferred from children when omitted) | boolean |
TreeSelect events
| Event | Description | Callback signature | Vue equivalent |
|---|---|---|---|
| onChange | Fired on selection change (single string / multiple string[]; undefined when a single selection is cleared) | (value: string | string[] | undefined) => void | update:modelValue / @change |
Keyboard interaction
The trigger is a real <button>: aria-haspopup="tree" plus aria-expanded marks the open state, and Enter / Space use native button activation. The panel is role="listbox" (with aria-multiselectable in multiple mode) and contains the LhTree's APG tree pattern keyboard navigation: Up / Down move focus, Right expands / enters children, Left collapses / returns to the parent, Home / End jump to the ends, Enter selects, and Space checks in multiple mode. Clicking outside or pressing Escape closes the panel, and focus returns to the trigger.
Interaction notes: in single mode, the first click on a non-leaf node only expands it (an already expanded parent is selected on the next click); in multiple mode the value is driven only by the checkboxes, the panel stays open for continuous checking, and parent / child checks cascade (disabled subtrees are skipped).
ref
forwardRef<HTMLDivElement> — the root element. LhTreeSelectInstance exposes open() / close() / toggle() / clear() / isOpen.
Styles
import '@lh-ui/react/style/tree-select'