Revert CascaderProps changes !49669 (#49741)

* Revert "fix: CascaderProps Multiple boolean type issue"

This reverts commit 91199fefc3.

* Revert "fix: eslint type issue"

This reverts commit 03146a9d69.

* Update index.tsx

Signed-off-by: 叶枫 <7971419+crazyair@users.noreply.github.com>

* test: update type test for cascader props

* feat: add panel

* feat: type

---------

Signed-off-by: 叶枫 <7971419+crazyair@users.noreply.github.com>
Co-authored-by: 叶枫 <7971419+crazyair@users.noreply.github.com>
Co-authored-by: 叶枫 <645381995@qq.com>
This commit is contained in:
Lim Yang Zhi 2024-07-06 14:23:15 +08:00 committed by GitHub
parent 8af7080fda
commit f94c23fdd2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 10 deletions

View File

@ -18,14 +18,14 @@ export type PanelPickType = Exclude<PickType, 'checkable'> | 'multiple' | 'rootC
export type CascaderPanelProps<
OptionType extends DefaultOptionType = DefaultOptionType,
ValueField extends keyof OptionType = keyof OptionType,
Multiple extends boolean = false,
Multiple extends boolean = boolean,
> = 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> & { multiple?: false })
| (CascaderPanelProps<OptionType, ValueField, true> & { multiple: true });
function CascaderPanel<

View File

@ -1,9 +1,9 @@
import * as React from 'react';
import type { BaseOptionType, CascaderAutoProps } from '..';
import type { BaseOptionType, CascaderAutoProps, CascaderProps } from '..';
import Cascader from '..';
import { render } from '../../../tests/utils';
import type { CascaderPanelAutoProps } from '../Panel';
import type { CascaderPanelAutoProps, CascaderPanelProps } from '../Panel';
describe('Cascader.typescript', () => {
it('options value', () => {
@ -86,15 +86,31 @@ describe('Cascader.typescript', () => {
});
it('multiple onChange', () => {
const { container } = render(
<Cascader multiple onChange={(values: (string | number | null)[][]) => values} />,
);
const { container } = render(<Cascader multiple onChange={(values) => values} />);
expect(container).toBeTruthy();
});
it('cascader props', () => {
// Incorrect usage, onChange value type is `value[]`
const cascaderProps: { props?: CascaderProps }[] = [{ props: { multiple: true } }];
expect(cascaderProps).toBeTruthy();
const { container } = render(<Cascader onChange={(value) => value} />);
expect(container).toBeTruthy();
});
it('cascader panel props', () => {
// Incorrect usage, onChange value type is `value[]`
const cascaderPanelProps: { props?: CascaderPanelProps }[] = [{ props: { multiple: true } }];
expect(cascaderPanelProps).toBeTruthy();
const { container } = render(<Cascader.Panel onChange={(value) => value} />);
expect(container).toBeTruthy();
});
it('props', () => {
const list: { props?: CascaderAutoProps }[] = [
{ props: { multiple: true, onChange: (value: (string | number | null)[][]) => value } },
{ props: { multiple: true, onChange: (value) => value } },
{ props: { multiple: false, onChange: (value) => value } },
];
expect(list).toBeTruthy();

View File

@ -139,8 +139,8 @@ export type CascaderAutoProps<
OptionType extends DefaultOptionType = DefaultOptionType,
ValueField extends keyof OptionType = keyof OptionType,
> =
| CascaderProps<OptionType, ValueField>
| (CascaderProps<OptionType, ValueField, true> & { multiple?: boolean });
| (CascaderProps<OptionType, ValueField> & { multiple?: false })
| (CascaderProps<OptionType, ValueField, true> & { multiple: true });
export interface CascaderRef {
focus: () => void;