Select 选择器
使用场景#
代替原生 select 元素。
单选与多选#
Select 支持以下两种方式来开启多选模式:
- 设置
multiple={true} - 使用
<Select.Multi />组件
在 TypeScript 项目中,我们推荐使用组件来切换单选(Select.Single)和多选(Select.Multi),类型提示和检查将更准确。
示例#
基本示例#
请选择
noInline
整行选择器#
请选择
noInline
轻量选择#
请选择
noInline
搜索#
请选择
inline
大数据量#
请选择
inline
错误状态#
请选择
noInline
多选#
请选择
inline
API#
Select.Single 与 Select.Multi 的区别仅在于 value 的类型不同(defaultValue, onChange 的类型也有相应的区别),其他 props 都相同。
| 字段 | 描述 | |
|---|---|---|
| defaultValue | string | string[] | |
| value | string | string[] | |
| onChange | (nextValue: string | string[], detail: {}) => void | |
| multiple | boolean是否多选 | |
| disabled | boolean是否禁用 | |
| dataSource | Array<string | { label, value }>数据源 | |
| 外观 | ||
| size | string选择器尺寸 | |
| style | CSSProperties | |
| className | string | |
| placeholder | string选择器值为空时,trigger 上的占位文本 | |
| hasArrow | boolean是否有下拉箭头 | |
| fill | boolean选择器宽度是否占满容器 | |
| shape | "simple" | "solid"选择器形状 | |
| hasClear | boolean是否有清除按钮 | |
| status | "normal" | "error" | "success" | "warning"选择器状态 | |
| containerProps | HTMLAttributes<HTMLDivElement> | |
| 弹层 | ||
| visible | boolean弹层是否打开 | |
| onRequestClose | (reason?: any) => void | |
| defaultVisible | boolean弹层是否默认打开 | |
| onRequestOpen | (reason?: any) => void | |
| autoWidth | boolean = true | |
| autoHeight | boolean = true | |
| autoScrollToFirstItemWhenOpen | boolean = true选择器弹层被打开时,是否自动滚动到第一个选中的元素 | |
| autoCloseAfterSelect | boolean选择元素时,是否自动关闭弹层。 单选模式下默认为 true,多选模式下默认为 false | |
| popupProps | PopupProps透传给 Popup 组件的 props | |
| 搜索 | ||
| showSearch | boolean是否支持搜索功能 | |
| searchValue | string搜索关键字 | |
| defaultSearchValue | string非受控用法,默认的搜索关键字 | |
| onSearch | (nextSearchValue: string, detail: { event: any; }) => void关键字修改回调 | |
| notFoundContent | ReactNode搜索结果为空时的展示内容 | |
