Forms
Cascader
Choose a value from a hierarchy one level at a time, such as country, region and city. The levels open as submenus, so the keyboard model is the familiar menu one.
import { Cascader } from '@reactloom/ui';Examples
Country, region, city
The trigger shows the path; the form submits the leaf value.
Office
Country, region, then city.
import { Cascader, type CascaderOption } from '@reactloom/ui';
import { useState } from 'react';
const places: CascaderOption[] = [
{
value: 'in',
label: 'India',
children: [
{ value: 'mh', label: 'Maharashtra', children: [{ value: 'mumbai', label: 'Mumbai' }, { value: 'pune', label: 'Pune' }] },
{ value: 'ka', label: 'Karnataka', children: [{ value: 'bengaluru', label: 'Bengaluru' }, { value: 'mysuru', label: 'Mysuru' }] },
],
},
{ value: 'jp', label: 'Japan', children: [{ value: 'tokyo', label: 'Tokyo' }, { value: 'osaka', label: 'Osaka' }] },
{ value: 'de', label: 'Germany', children: [{ value: 'berlin', label: 'Berlin' }, { value: 'munich', label: 'Munich', disabled: true }] },
];
export default function Example() {
const [value, setValue] = useState<string | null>('pune');
return (
<div style={{ width: '100%', maxWidth: 320 }}>
<Cascader label="Office" options={places} value={value} onValueChange={setValue} name="office" description="Country, region, then city." />
</div>
);
}Leaf only
showLeafOnly shows just the chosen item.
Category
import { Cascader } from '@reactloom/ui';
export default function Example() {
return (
<div style={{ width: '100%', maxWidth: 320 }}>
<Cascader
label="Category"
showLeafOnly
defaultValue="laptops"
options={[
{ value: 'electronics', label: 'Electronics', children: [{ value: 'laptops', label: 'Laptops' }, { value: 'phones', label: 'Phones' }] },
{ value: 'home', label: 'Home', children: [{ value: 'kitchen', label: 'Kitchen' }, { value: 'garden', label: 'Garden' }] },
]}
/>
</div>
);
}API reference
| Prop | Type | Default |
|---|---|---|
optionsrequired{ value, label, children?, disabled?, icon? }; leaves are the values. | CascaderOption[] | — |
value / defaultValueThe chosen leaf. | string | null | — |
onValueChange | (value, path) => void | — |
separator | string | ' / ' |
showLeafOnly | boolean | false |
nameSubmitted as a hidden input. | string | — |
label · description · error · required · disabled · size · placeholderAs on Select. | | — |
classNames · stylesroot, label, description, trigger, value, indicator, error. | Partial<Record<CascaderSlot, …>> | — |
Customization
Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.
Slot class names
Add classes to inner parts with classNames (className is shorthand for root): root, label, description, trigger, value, indicator, error.
Accessibility
- A menu button: the trigger’s name includes the label and the current path.
- Each level is a submenu; → opens it, ← returns, Enter chooses a leaf.
| Key | Action |
|---|---|
| Enter / Space / ↓ | Open the first level |
| ↑ / ↓ | Move |
| → | Open the next level |
| ← | Back to the previous level |
| Enter | Choose a leaf |
| Escape | Close |
Usage guidelines
Do
- Use for three or more levels where each choice narrows the next.
Don’t
- Don’t use for flat lists; use Select or Combobox.
- For searching deep trees, use TreeSelect with searchable.