Cascader
A cascading selection box for hierarchical data.
When To Use
- When you need to select from a set of a hierarchical structure. Such as province/city/district, company level, and classification.
- When selecting from a large data set, with multi-stage classification separated for easy selection.
- Chooses cascade items in one float layer for a better user experience.
Usage
Basic
Cascade selection box for selecting province/city/district.
astro
---
import Cascader from '@/components/data-entry/Cascader.astro';
const options = [
{
value: 'zhejiang',
label: 'Zhejiang',
children: [
{
value: 'hangzhou',
label: 'Hangzhou',
children: [{ value: 'xihu', label: 'West Lake' }],
},
],
},
{
value: 'jiangsu',
label: 'Jiangsu',
children: [
{
value: 'nanjing',
label: 'Nanjing',
children: [{ value: 'zhonghuamen', label: 'Zhong Hua Men' }],
},
],
},
];
---
<Cascader options={options} placeholder="Please select" class="max-w-xs" /> Disabled option
Disable option by specifying the disabled property in options.
astro
---
import Cascader from '@/components/data-entry/Cascader.astro';
const options = [
{
value: 'zhejiang',
label: 'Zhejiang',
children: [
{
value: 'hangzhou',
label: 'Hangzhou',
children: [{ value: 'xihu', label: 'West Lake' }],
},
],
},
{
value: 'jiangsu',
label: 'Jiangsu',
disabled: true,
children: [
{
value: 'nanjing',
label: 'Nanjing',
children: [{ value: 'zhonghuamen', label: 'Zhong Hua Men' }],
},
],
},
];
---
<Cascader options={options} placeholder="Please select" class="max-w-xs" /> Default value
Specifies default value by an array.
astro
---
import Cascader from '@/components/data-entry/Cascader.astro';
const options = [
{
value: 'zhejiang',
label: 'Zhejiang',
children: [
{
value: 'hangzhou',
label: 'Hangzhou',
children: [{ value: 'xihu', label: 'West Lake' }],
},
],
},
{
value: 'jiangsu',
label: 'Jiangsu',
children: [
{
value: 'nanjing',
label: 'Nanjing',
children: [{ value: 'zhonghuamen', label: 'Zhong Hua Men' }],
},
],
},
];
---
<Cascader options={options} value={['zhejiang', 'hangzhou', 'xihu']} placeholder="Please select" class="max-w-xs" /> API Reference
| Property | Description | Type | Default |
|---|---|---|---|
| options | The hierarchical options data. | CascaderOption[] | [] |
| placeholder | The input placeholder text. | string | "Select..." |
| value | The initial selected value path. | string[] | [] |