Cascader
A multi-level cascading selector with controlled / uncontrolled modes, multiple selection, selecting at any level, path echo, search filtering, and keyboard navigation.
Basic usage
Current value: (not selected)
import { useState } from 'react'
import { LhCascader } from '@lh-ui/react'
import type { LhCascaderNode } from '@lh-ui/react'
const options: LhCascaderNode[] = [
{
label: 'Zhejiang',
value: 'zhejiang',
children: [
{
label: 'Hangzhou',
value: 'hangzhou',
children: [{ label: 'West Lake', value: 'xihu' }],
},
],
},
{
label: 'Jiangsu',
value: 'jiangsu',
children: [
{
label: 'Nanjing',
value: 'nanjing',
children: [{ label: 'Fuzimiao', value: 'fuzimiao' }],
},
],
},
]
export default function Demo() {
const [value, setValue] = useState<(string | number)[]>([])
return (
<LhCascader
value={value}
options={options}
placeholder="Select a region"
onChange={(next) => setValue(next)}
/>
)
}
Cascader Props
| Prop | Description | Type | Options | Default |
|---|---|---|---|---|
| value | Controlled value (array of path values) | (string | number)[] | — | — |
| defaultValue | Uncontrolled default value | (string | number)[] | — | — |
| options | Cascading option tree | LhCascaderNode[] | — | [] |
| placeholder | Placeholder | string | — | Locale pack fallback |
| disabled | Whether to disable | boolean | — | false |
| readonly | Read-only | boolean | — | false |
| clearable | Whether to be clearable | boolean | — | true |
| size | Size | 'small' | 'medium' | 'large' | — | Follows ConfigProvider |
| showAllLevels | Whether the echo shows the full path | boolean | — | true |
| checkStrictly | Allow selecting any node | boolean | — | false |
| emitPath | Whether the value carries the full path | boolean | — | true |
| multiple | Multiple selection | boolean | — | false |
| cascading | Expand children on hover | boolean | — | true |
| separator | Path separator | string | — | '/' |
| collapseTags | Collapse multiple-selection tags | boolean | — | false |
| filterable | Whether to be searchable | boolean | — | false |
| itemConfig | Custom field aliases | LhCascaderItemConfig | — | {} |
| ariaLabel | Accessibility label | string | — | — |
| placement | Panel placement | LhPlacement | — | 'bottom-start' |
| sx | Shorthand layout props | SxProps | — | — |
LhCascaderNode
| Prop | Description | Type |
|---|---|---|
| label | Node display text | string |
| value | Node value | string | number |
| disabled | Disable this node | boolean |
| leaf | Leaf marker (explicitly declares whether the node is a leaf) | boolean |
| children | Child nodes | LhCascaderNode[] |
Cascader events
| Event | Description | Callback signature | Vue equivalent |
|---|---|---|---|
| onChange | Fired on selection change (the value plus the full node path; the path is null for multiple selection / clearing) | (value: (string | number)[], path: LhCascaderNode[] | null) => void | @change |
| onClear | Fired when cleared | () => void | — |
Keyboard interaction
The trigger is role="combobox": ArrowDown / ArrowUp open the panel and move focus to the first / last column, and Escape collapses it and returns focus to the input. The panel is role="dialog", and each column is a role="listbox": Up / Down move within a column (skipping disabled items), Right expands / enters the next column, Left goes back to the previous column, and Enter / Space act like a click. In multiple mode, pressing Backspace on an empty input removes the last selected item.
ref
forwardRef<HTMLDivElement> — the trigger root element. LhCascaderInstance exposes open() / close() / toggle() / clear() / isOpen.
Styles
import '@lh-ui/react/style/cascader'