Skip to content

Commit

Permalink
fix: cascader's onChange ts adapts to single and multiple (ant-design…
Browse files Browse the repository at this point in the history
…#33947)

* fix to: cascader's multiple determines the declaration of onChange

* fix: cascader's onChange ts adapts to single and multiple

* test: fix
  • Loading branch information
babycannotsay authored and heiyu4585 committed Feb 24, 2022
1 parent 7d3dfbb commit 7d45dd3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
14 changes: 14 additions & 0 deletions components/cascader/__tests__/type.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,18 @@ describe('Cascader.typescript', () => {
);
expect(wrapper).toBeTruthy();
});

it('single onChange', () => {
const wrapper = mount(
<Cascader multiple={false} onChange={(values: (string | number)[]) => values} />,
);
expect(wrapper).toBeTruthy();
});

it('multiple onChange', () => {
const wrapper = mount(
<Cascader multiple onChange={(values: (string | number)[][]) => values} />,
);
expect(wrapper).toBeTruthy();
});
});
15 changes: 12 additions & 3 deletions components/cascader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import * as React from 'react';
import classNames from 'classnames';
import RcCascader from 'rc-cascader';
import type {
CascaderProps as RcCascaderProps,
SingleCascaderProps as RcSingleCascaderProps,
MultipleCascaderProps as RcMultipleCascaderProps,
ShowSearchType,
FieldNames,
BaseOptionType,
Expand Down Expand Up @@ -80,8 +81,16 @@ const defaultSearchRender: ShowSearchType['render'] = (inputValue, path, prefixC
return optionList;
};

export interface CascaderProps<DataNodeType>
extends Omit<RcCascaderProps, 'checkable' | 'options'> {
type SingleCascaderProps = Omit<RcSingleCascaderProps, 'checkable' | 'options'> & {
multiple?: false;
};
type MultipleCascaderProps = Omit<RcMultipleCascaderProps, 'checkable' | 'options'> & {
multiple: true;
};

type UnionCascaderProps = SingleCascaderProps | MultipleCascaderProps;

export type CascaderProps<DataNodeType> = UnionCascaderProps & {
multiple?: boolean;
size?: SizeType;
bordered?: boolean;
Expand Down

0 comments on commit 7d45dd3

Please sign in to comment.