components/cascader/index.zh-CN.md
<code src="./demo/basic.tsx">基本</code> <code src="./demo/default-value.tsx">默认值</code> <code src="./demo/custom-trigger.tsx">可以自定义显示</code> <code src="./demo/hover.tsx">移入展开</code> <code src="./demo/disabled-option.tsx">禁用选项</code> <code src="./demo/change-on-select.tsx">选择即改变</code> <code src="./demo/multiple.tsx">多选</code> <code src="./demo/showCheckedStrategy.tsx">自定义回填方式</code> <code src="./demo/size.tsx">大小</code> <code src="./demo/custom-render.tsx">自定义已选项</code> <code src="./demo/search.tsx">搜索</code> <code src="./demo/lazy.tsx">动态加载选项</code> <code src="./demo/fields-name.tsx">自定义字段名</code> <code src="./demo/suffix.tsx" version="5.22.0">前后缀</code> <code src="./demo/custom-dropdown.tsx">扩展菜单</code> <code src="./demo/placement.tsx">弹出位置</code> <code src="./demo/variant.tsx" version="5.13.0">形态变体</code> <code src="./demo/status.tsx">自定义状态</code> <code src="./demo/style-class.tsx" version="6.0.0">自定义语义结构的样式和类</code> <code src="./demo/panel.tsx" version=">= 5.10.0">面板使用</code> <code src="./demo/ellipsis-debug.tsx" debug>菜单项省略样式调试</code> <code src="./demo/render-panel.tsx" debug>_InternalPanelDoNotUseOrYouWillBeFired</code> <code src="./demo/component-token.tsx" debug>Component Token</code>
通用属性参考:通用属性
<Cascader options={options} onChange={onChange} />
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| allowClear | 支持清除 | boolean | { clearIcon?: ReactNode } | true | 5.8.0: 支持对象形式 |
是否在选中项后清空搜索框,只在 multiple 为 true 时有效 | boolean | true | 5.9.0 | |
是否带边框,请使用 variant 替代 | boolean | true | - | |
| changeOnSelect | 单选时生效(multiple 下始终都可以选择),点选每级菜单选项值都会发生变化。 | boolean | false | |
| className | 自定义类名 | string | - | |
| classNames | 用于自定义组件内部各语义化结构的 class,支持对象或函数 | Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string> | - | |
| defaultOpen | 是否默认展示浮层 | boolean | - | |
| defaultValue | 默认的选中项 | string[] | number[] | [] | |
| disabled | 禁用 | boolean | false | |
| displayRender | 选择后展示的渲染函数 | (label, selectedOptions) => ReactNode | label => label.join(/) | multiple: 4.18.0 |
| tagRender | 自定义 tag 内容 render,仅在多选时生效 | ({ label: string, onClose: function, value: string }) => ReactNode | - | |
自定义浮层类名,使用 classNames.popup.root 替换 | string | - | 4.23.0 | |
自定义浮层类名,请使用 classNames.popup.root 替代 | string | - | - | |
自定义下拉框内容,请使用 popupRender 替换 | (menus: ReactNode) => ReactNode | - | 4.4.0 | |
| popupRender | 自定义下拉框内容 | (menus: ReactNode) => ReactNode | - | |
下拉菜单的 style 属性,使用 styles.popup.root 替换 | CSSProperties | - | ||
| expandIcon | 自定义次级菜单展开图标 | ReactNode | - | 4.4.0 |
| expandTrigger | 次级菜单的展开方式,可选 'click' 和 'hover' | string | click | |
| fieldNames | 自定义 options 中 label value children 的字段 | object | { label: label, value: value, children: children } | |
| getPopupContainer | 菜单渲染父节点。默认渲染到 body 上,如果你遇到菜单滚动定位问题,试试修改为滚动的区域,并相对其定位。示例 | function(triggerNode) | () => document.body | |
| loadData | 用于动态加载选项,无法与 showSearch 一起使用 | (selectedOptions) => void | - | |
| loadingIcon | 自定义的加载图标 | ReactNode | - | |
| maxTagCount | 最多显示多少个 tag,响应式模式会对性能产生损耗 | number | responsive | - | 4.17.0 |
| maxTagPlaceholder | 隐藏 tag 时显示的内容 | ReactNode | function(omittedValues) | - | 4.17.0 |
| maxTagTextLength | 最大显示的 tag 文本长度 | number | - | 4.17.0 |
| notFoundContent | 当下拉列表为空时显示的内容 | ReactNode | Not Found | |
| open | 控制浮层显隐 | boolean | - | 4.17.0 |
| options | 可选项数据源 | Option[] | - | |
| placeholder | 输入框占位文本 | string | - | |
| placement | 浮层预设位置 | bottomLeft bottomRight topLeft topRight | bottomLeft | 4.17.0 |
| prefix | 自定义前缀 | ReactNode | - | 5.22.0 |
是否显示箭头图标,请使用 suffixIcon={null} 替代 | boolean | true | - | |
| showSearch | 在选择框中显示搜索框 | boolean | Object | false | |
| size | 输入框大小 | large | medium | small | medium | |
| status | 设置校验状态 | 'error' | 'warning' | - | 4.19.0 |
| styles | 用于自定义组件内部各语义化结构的行内 style,支持对象或函数 | Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties> | - | |
| suffixIcon | 自定义的选择框后缀图标 | ReactNode | - | |
| value | 指定选中项 | string[] | number[] | - | |
| variant | 形态变体 | outlined | borderless | filled | underlined | outlined | 5.13.0 | underlined: 5.24.0 |
| onChange | 选择完成后的回调 | (value, selectedOptions) => void | - | |
显示/隐藏浮层的回调,请使用 onOpenChange 替换 | (value) => void | - | 4.17.0 | |
| onOpenChange | 显示/隐藏浮层的回调 | (value) => void | - | |
显示或隐藏浮层的回调,请使用 onOpenChange 替代 | (value) => void | - | - | |
| multiple | 支持多选节点 | boolean | - | 4.17.0 |
| removeIcon | 自定义的多选框清除图标 | ReactNode | - | |
| showCheckedStrategy | 定义选中项回填的方式(仅在 multiple 为 true 时生效)。Cascader.SHOW_CHILD: 只显示选中的子节点。Cascader.SHOW_PARENT: 只显示父节点(当父节点下所有子节点都选中时)。 | Cascader.SHOW_PARENT | Cascader.SHOW_CHILD | Cascader.SHOW_PARENT | 4.20.0 |
设置搜索的值,需要与 showSearch 配合使用 | string | - | 4.17.0 | |
| 监听搜索,返回输入的值 | (search: string) => void | - | 4.17.0 | |
下拉菜单列的样式,请使用 styles.popup.listItem 替换 | CSSProperties | - | ||
下拉菜单列的样式,请使用 styles.popup.listItem 替换 | CSSProperties | - | ||
| optionRender | 自定义渲染下拉选项 | (option: Option) => React.ReactNode | - | 5.16.0 |
showSearch 为对象时,其中的字段:
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| autoClearSearchValue | 是否在选中项后清空搜索框,只在 multiple 为 true 时有效 | boolean | true | 5.9.0 |
| filter | 接收 inputValue path 两个参数,当 path 符合筛选条件时,应返回 true,反之则返回 false | function(inputValue, path): boolean | - | |
| limit | 搜索结果展示数量 | number | false | 50 | |
| matchInputWidth | 搜索结果列表是否与输入框同宽(效果) | boolean | true | |
| render | 用于渲染 filter 后的选项 | function(inputValue, path): ReactNode | - | |
| sort | 用于排序 filter 后的选项 | function(a, b, inputValue) | - | |
| searchValue | 设置搜索的值,需要与 showSearch 配合使用 | string | - | 4.17.0 |
| onSearch | 监听搜索,返回输入的值 | (search: string) => void | - | 4.17.0 |
interface Option {
value: string | number;
label?: React.ReactNode;
disabled?: boolean;
children?: Option[];
// 标记是否为叶子节点,设置了 `loadData` 时有效
// 设为 `false` 时会强制标记为父节点,即使当前节点没有 children,也会显示展开图标
isLeaf?: boolean;
}
| 名称 | 描述 | 版本 |
|---|---|---|
| blur() | 移除焦点 | |
| focus() | 获取焦点 |
注意,如果需要获得中国省市区数据,可以参考 china-division。
<code src="./demo/_semantic.tsx" simplify="true"></code>
<ComponentTokenTable component="Cascader"></ComponentTokenTable>