From e7ac69edeb09fd6f6275faaff38de2bcbded6e64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Wed, 24 Nov 2021 17:45:13 +0800 Subject: [PATCH] fix: Cascader typescript (#33008) * chore: Cascsader add missing suffixIcon * chore: export CascaderRef * chore: Casacer type --- components/cascader/__tests__/type.test.tsx | 34 ++++++++++++++++++++- components/cascader/index.tsx | 20 +++++++++--- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/components/cascader/__tests__/type.test.tsx b/components/cascader/__tests__/type.test.tsx index b3330ffdd8..260c4de3d8 100644 --- a/components/cascader/__tests__/type.test.tsx +++ b/components/cascader/__tests__/type.test.tsx @@ -1,5 +1,6 @@ +import { mount } from 'enzyme'; import * as React from 'react'; -import Cascader from '..'; +import Cascader, { BasicDataNode } from '..'; describe('Cascader.typescript', () => { it('options value', () => { @@ -42,4 +43,35 @@ describe('Cascader.typescript', () => { expect(result).toBeTruthy(); }); + + it('suffixIcon', () => { + const wrapper = mount(} />); + expect(wrapper).toBeTruthy(); + }); + + it('Generic', () => { + interface MyOptionData extends BasicDataNode { + customizeLabel: string; + customizeValue: string; + customizeChildren?: MyOptionData[]; + } + + const wrapper = mount( + + options={[ + { + customizeLabel: 'Bamboo', + customizeValue: 'bamboo', + customizeChildren: [ + { + customizeLabel: 'Little', + customizeValue: 'little', + }, + ], + }, + ]} + />, + ); + expect(wrapper).toBeTruthy(); + }); }); diff --git a/components/cascader/index.tsx b/components/cascader/index.tsx index d12acd1223..6ab34aa3ac 100644 --- a/components/cascader/index.tsx +++ b/components/cascader/index.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import classNames from 'classnames'; import RcCascader from 'rc-cascader'; import type { CascaderProps as RcCascaderProps } from 'rc-cascader'; -import type { ShowSearchType, FieldNames } from 'rc-cascader/lib/interface'; +import type { ShowSearchType, FieldNames, DataNode } from 'rc-cascader/lib/interface'; import omit from 'rc-util/lib/omit'; import RightOutlined from '@ant-design/icons/RightOutlined'; import RedoOutlined from '@ant-design/icons/RedoOutlined'; @@ -19,6 +19,8 @@ import { getTransitionName } from '../_util/motion'; // - Hover opacity style // - Search filter match case +export type BasicDataNode = Omit; + export type FieldNamesType = FieldNames; export type FilledFieldNamesType = Required; @@ -72,18 +74,22 @@ const defaultSearchRender: ShowSearchType['render'] = (inputValue, path, prefixC return optionList; }; -export interface CascaderProps extends Omit { +export interface CascaderProps + extends Omit { multiple?: boolean; size?: SizeType; bordered?: boolean; + + suffixIcon?: React.ReactNode; + options?: DataNodeType[]; } -interface CascaderRef { +export interface CascaderRef { focus: () => void; blur: () => void; } -const Cascader = React.forwardRef((props: CascaderProps, ref: React.Ref) => { +const Cascader = React.forwardRef((props: CascaderProps, ref: React.Ref) => { const { prefixCls: customizePrefixCls, size: customizeSize, @@ -225,7 +231,11 @@ const Cascader = React.forwardRef((props: CascaderProps, ref: React.Ref ); -}); +}) as (( + props: React.PropsWithChildren> & { ref?: React.Ref }, +) => React.ReactElement) & { + displayName: string; +}; Cascader.displayName = 'Cascader';