mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-15 08:59:15 +08:00
14a1e6bd51
* feat: tsconfig enable strict * feat: add no-explicit-any * feat: strict * feat: as THEME * feat: 优化 keys 类型写法 * feat: demo remove any * feat: as number * feat: this any * feat: add eslint * feat: cascader * feat: props any * feat: remove any * feat: remove any * feat: any 提示错误 * feat: remove any * feat: add eslint * feat: 允许 T = any 存在 * feat: color funciton * feat: 恢复 lint * feat: merge master * feat: as ReactElement * feat: type
75 lines
1.5 KiB
TypeScript
75 lines
1.5 KiB
TypeScript
import React from 'react';
|
|
import { Cascader } from 'antd';
|
|
import type { CascaderProps, GetProp } from 'antd';
|
|
import type { SingleCascaderProps } from 'antd/es/cascader';
|
|
|
|
type DefaultOptionType = GetProp<CascaderProps, 'options'>[number];
|
|
|
|
interface Option {
|
|
value: string;
|
|
label: string;
|
|
children?: Option[];
|
|
disabled?: boolean;
|
|
}
|
|
|
|
const options: Option[] = [
|
|
{
|
|
value: 'zhejiang',
|
|
label: 'Zhejiang',
|
|
children: [
|
|
{
|
|
value: 'hangzhou',
|
|
label: 'Hangzhou',
|
|
children: [
|
|
{
|
|
value: 'xihu',
|
|
label: 'West Lake',
|
|
},
|
|
{
|
|
value: 'xiasha',
|
|
label: 'Xia Sha',
|
|
disabled: true,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
value: 'jiangsu',
|
|
label: 'Jiangsu',
|
|
children: [
|
|
{
|
|
value: 'nanjing',
|
|
label: 'Nanjing',
|
|
children: [
|
|
{
|
|
value: 'zhonghuamen',
|
|
label: 'Zhong Hua men',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
];
|
|
|
|
const onChange: SingleCascaderProps<Option>['onChange'] = (value, selectedOptions) => {
|
|
console.log(value, selectedOptions);
|
|
};
|
|
|
|
const filter = (inputValue: string, path: DefaultOptionType[]) =>
|
|
path.some(
|
|
(option) => (option.label as string).toLowerCase().indexOf(inputValue.toLowerCase()) > -1,
|
|
);
|
|
|
|
const App: React.FC = () => (
|
|
<Cascader
|
|
options={options}
|
|
onChange={onChange}
|
|
placeholder="Please select"
|
|
showSearch={{ filter }}
|
|
onSearch={(value) => console.log(value)}
|
|
/>
|
|
);
|
|
|
|
export default App;
|