mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 11:08:45 +08:00
fix: fix cascader type (#48879)
* fix: fix cascader type * feat: add test * feat: test * feat: panel * feat: panel * feat: CascaderAutoProps
This commit is contained in:
parent
470e8a8e0a
commit
b15a2f2bfc
@ -21,11 +21,17 @@ export type CascaderPanelProps<
|
||||
Multiple extends boolean = false,
|
||||
> = Pick<CascaderProps<OptionType, ValueField, Multiple>, PanelPickType>;
|
||||
|
||||
export type CascaderPanelAutoProps<
|
||||
OptionType extends DefaultOptionType = DefaultOptionType,
|
||||
ValueField extends keyof OptionType = keyof OptionType,
|
||||
> =
|
||||
| CascaderPanelProps<OptionType, ValueField>
|
||||
| (CascaderPanelProps<OptionType, ValueField, true> & { multiple: true });
|
||||
|
||||
function CascaderPanel<
|
||||
OptionType extends DefaultOptionType = DefaultOptionType,
|
||||
ValueField extends keyof OptionType = keyof OptionType,
|
||||
Multiple extends boolean = false,
|
||||
>(props: CascaderPanelProps<OptionType, ValueField, Multiple>) {
|
||||
>(props: CascaderPanelAutoProps<OptionType, ValueField>) {
|
||||
const {
|
||||
prefixCls: customizePrefixCls,
|
||||
className,
|
||||
|
@ -1,8 +1,9 @@
|
||||
import * as React from 'react';
|
||||
|
||||
import type { BaseOptionType } from '..';
|
||||
import type { BaseOptionType, CascaderAutoProps } from '..';
|
||||
import Cascader from '..';
|
||||
import { render } from '../../../tests/utils';
|
||||
import type { CascaderPanelAutoProps } from '../Panel';
|
||||
|
||||
describe('Cascader.typescript', () => {
|
||||
it('options value', () => {
|
||||
@ -88,4 +89,17 @@ describe('Cascader.typescript', () => {
|
||||
const { container } = render(<Cascader multiple onChange={(values) => values} />);
|
||||
expect(container).toBeTruthy();
|
||||
});
|
||||
it('props', () => {
|
||||
const list: { props?: CascaderAutoProps }[] = [
|
||||
{ props: { multiple: true, onChange: (value) => value } },
|
||||
{ props: { multiple: false, onChange: (value) => value } },
|
||||
];
|
||||
expect(list).toBeTruthy();
|
||||
|
||||
const list2: { props?: CascaderPanelAutoProps }[] = [
|
||||
{ props: { multiple: true, onChange: (value) => value } },
|
||||
{ props: { multiple: false, onChange: (value) => value } },
|
||||
];
|
||||
expect(list2).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
@ -135,6 +135,12 @@ export interface CascaderProps<
|
||||
*/
|
||||
variant?: Variant;
|
||||
}
|
||||
export type CascaderAutoProps<
|
||||
OptionType extends DefaultOptionType = DefaultOptionType,
|
||||
ValueField extends keyof OptionType = keyof OptionType,
|
||||
> =
|
||||
| CascaderProps<OptionType, ValueField>
|
||||
| (CascaderProps<OptionType, ValueField, true> & { multiple: true });
|
||||
|
||||
export interface CascaderRef {
|
||||
focus: () => void;
|
||||
@ -348,9 +354,8 @@ const Cascader = React.forwardRef<CascaderRef, CascaderProps<any>>((props, ref)
|
||||
}) as unknown as (<
|
||||
OptionType extends DefaultOptionType = DefaultOptionType,
|
||||
ValueField extends keyof OptionType = keyof OptionType,
|
||||
Multiple extends boolean = false,
|
||||
>(
|
||||
props: React.PropsWithChildren<CascaderProps<OptionType, ValueField, Multiple>> &
|
||||
props: React.PropsWithChildren<CascaderAutoProps<OptionType, ValueField>> &
|
||||
React.RefAttributes<CascaderRef>,
|
||||
) => React.ReactElement) & {
|
||||
displayName: string;
|
||||
|
@ -27,7 +27,8 @@ export type { CardProps } from './card';
|
||||
export { default as Carousel } from './carousel';
|
||||
export type { CarouselProps } from './carousel';
|
||||
export { default as Cascader } from './cascader';
|
||||
export type { CascaderProps } from './cascader';
|
||||
export type { CascaderProps, CascaderAutoProps } from './cascader';
|
||||
export type { CascaderPanelProps, CascaderPanelAutoProps } from './cascader/Panel';
|
||||
export { default as Checkbox } from './checkbox';
|
||||
export type { CheckboxOptionType, CheckboxProps, CheckboxRef } from './checkbox';
|
||||
export { default as Col } from './col';
|
||||
|
Loading…
Reference in New Issue
Block a user