Cascader component
npm install @uiw/react-cascaderCascader 级联选择
===




级联选择框。v4.16.0中添加
``jsx`
import { Cascader, Row, Col } from 'uiw';
// or
import Cascader from '@uiw/react-cascader';
`jsx mdx:preview&bg=#fff
import React from 'react';
import { Cascader, Row } from 'uiw';
const Demo = () => {
const options = [
{
label: '上海市',
value: 1,
children: [
{
label: '徐汇区',
value: 4,
children: [
{ label: '半淞园路街道', value: 6 },
{ label: '南京东路街道', value: 7 },
{ label: '外滩街道', value: 8 },
]
},
]
},
{
label: '北京市',
value: 9,
children: [
{
label: '崇文区',
value: 12,
children: [
{ label: '东花市街道', value: 13 },
{ label: '体育馆路街道', value: 14 },
{ label: '前门街道', value: 15 },
]
},
]
},
];
return (
allowClear={true}
placeholder="请选择"
value={[1, 4, 7]}
option={options}
onChange={(value, seleteds) => console.log(value, seleteds)}
/>
allowClear={true}
placeholder="请选择"
value={[1, 4, 7]}
disabled={true}
option={options}
onChange={(value, seleteds) => console.log(value, seleteds)}
/>
)
};
export default Demo
`
`jsx mdx:preview
import React from 'react';
import { Cascader, Row } from 'uiw';
const Demo = () => {
const options = [
{
label: '尺寸', value: 1,
children: [
{
label: 'size',
value: 2,
children: [
{ label: '小尺寸', value: 3 },
{ label: '默认尺寸', value: 4 },
{ label: '大尺寸', value: 5 },
]
},
]
}
];
return (
value={[1, 2, 3]}
option={options}
size="small"
/>
value={[1, 2, 4]}
option={options}
/>
value={[1, 2, 5]}
option={options}
size="large"
/>
)
};
export default Demo
`
`jsx mdx:preview&bg=#fff
import React from 'react';
import { Cascader } from 'uiw';
const Demo = () => {
const options = [
{
label: '上海市',
value: 1,
children: [
{
label: '徐汇区',
value: 4,
children: [
{ label: '半淞园路街道', value: 6 },
{ label: '南京东路街道', value: 7 },
{ label: '外滩街道', value: 8 },
]
},
]
},
{
label: '北京市',
value: 9,
children: [
{
label: '崇文区',
value: 12,
children: [
{ label: '东花市街道', value: 13 },
{ label: '体育馆路街道', value: 14 },
{ label: '前门街道', value: 15 },
]
},
]
},
];
return (
allowClear={true}
placeholder="请选择"
value={[1, 4, 7]}
option={options}
onChange={(value, seleteds) => console.log(value, seleteds)}
onSearch={(text)=> console.log('text', text)}
/>
)
};
export default Demo
`
`jsx mdx:preview&bg=#fff
import React from 'react';
import { Cascader, Row } from 'uiw';
const Demo = () => {
const options = [
{
label: '上海市',
value: 1,
children: [
{
label: '徐汇区',
value: 4,
children: [
{ label: '半淞园路街道', value: 6 },
{ label: '南京东路街道', value: 7 },
{ label: '外滩街道', value: 8 },
]
},
]
},
{
label: '北京市',
value: 9,
children: [
{
label: '崇文区',
value: 12,
children: [
{ label: '东花市街道', value: 13 },
{ label: '体育馆路街道', value: 14 },
{ label: '前门街道', value: 15 },
]
},
]
},
];
return (
expandTrigger="hover"
allowClear={true}
placeholder="请选择"
value={[1, 4, 7]}
option={options}
onChange={(value, seleteds) => console.log(value, seleteds)}
onSearch={true}
/>
)
};
export default Demo
`
`jsx mdx:preview&bg=#fff
import React from 'react';
import { Form, Row, Col, Cascader, Button } from 'uiw';
const Demo = () => {
const options = [
{
label: '上海市',
value: 1,
children: [
{
label: '徐汇区',
value: 4,
children: [
{ label: '半淞园路街道', value: 6 },
{ label: '南京东路街道', value: 7 },
{ label: '外滩街道', value: 8 },
]
},
]
},
{
label: '北京市',
value: 9,
children: [
{
label: '崇文区',
value: 12,
children: [
{ label: '东花市街道', value: 13 },
{ label: '体育馆路街道', value: 14 },
{ label: '前门街道', value: 15 },
]
},
]
},
];
return (
,
});
}}
fields={{
cascader: {
initialValue:[1, 4, 7],
children: (
allowClear={true}
onSearch={true}
placeholder="请选择"
option={options}
onChange={(value, seleteds) => console.log(value, seleteds)}
/>
)
},
}}
>
{({ fields, state, canSubmit }) => {
return (
{fields.cascader}
|
|
{JSON.stringify(state.current, null, 2)}
|
)
}}
Props
| 参数 | 说明 | 类型 | 默认值 | 版本 |
| ---- | ---- | ---- | ---- | ---- |
| allowClear | 支持清除 | Boolean |
false | - |
| disabled | 禁用选择器 | Boolean | false | - |
| placeholder | 选择框默认文字 | String | - | - |
| option | 选项菜单 | { value: String \| Number, label: React.ReactNode, children: Array} | - | - |
| value | 指定当前选中的条目,多选时为一个数组 | String[] \| Number[] | - | - |
| onChange | 选中选项调用此函数 | function( isSeleted, value, selectedOptions) | - | - |
| onSearch | 开启搜索选项 | functionon(searchText) \| Boolean | - | v4.16.1 |
| size | 选择框尺寸 | Enum{large, default, small } | default | v17.0.1 |
| inputProps | 传给Input组件的参数 | Object | - | v17.0.1 |
| expandTrigger | 子集菜单的展开方式,'click' 和 'hover' | String | click` | v4.18.2 |