Skip to main content

TreeSelect

A selector combining a dropdown trigger with a tree panel: single selection returns string, multiple selection (checkboxes) returns string[].

Basic usage​

Single / multiple selection

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​

PropDescriptionTypeOptionsDefault
dataTree dataLhTreeNode[]—[]
valueControlled value (single string / multiple string[])string | string[]——
defaultValueUncontrolled default valuestring | string[]——
multipleMultiple selection (shows checkboxes; value is the array of checked keys)boolean—false
disabledWhether to disableboolean—false
placeholderPlaceholderstring—Locale pack fallback
teleportedWhether the panel mounts to body (false renders in place)boolean—true
sxShorthand layout propsSxProps——

LhTreeNode​

PropDescriptionType
keyUnique keystring
labelDisplay textstring
childrenChild nodesLhTreeNode[]
disabledDisable this node (disabled subtrees are skipped in cascading checks)boolean
isLeafLeaf marker (inferred from children when omitted)boolean

TreeSelect events​

EventDescriptionCallback signatureVue equivalent
onChangeFired on selection change (single string / multiple string[]; undefined when a single selection is cleared)(value: string | string[] | undefined) => voidupdate: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'