From 51c936e7b44b0cd485fef32867658d638039cfec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=B1=AA?= <1844749591@qq.com> Date: Sun, 5 Jan 2025 16:32:02 +0800 Subject: [PATCH 1/5] feat: retire deprecated api --- docs/examples/common.less | 10 ---------- docs/examples/custom-icon.tsx | 6 ++---- src/BaseSelect/index.tsx | 7 ------- src/Select.tsx | 10 +--------- src/hooks/useAllowClear.tsx | 10 +++------- src/utils/warningPropsUtil.ts | 6 ------ tests/Select.test.tsx | 8 ++++---- 7 files changed, 10 insertions(+), 47 deletions(-) delete mode 100644 docs/examples/common.less diff --git a/docs/examples/common.less b/docs/examples/common.less deleted file mode 100644 index d78a563b4..000000000 --- a/docs/examples/common.less +++ /dev/null @@ -1,10 +0,0 @@ -// input { -// // height: 24px; -// // line-height: 24px; -// border: 1px solid #333; -// border-radius: 4px; -// } - -// button { -// border: 1px solid #333; -// } diff --git a/docs/examples/custom-icon.tsx b/docs/examples/custom-icon.tsx index b82aff553..4d3112d75 100644 --- a/docs/examples/custom-icon.tsx +++ b/docs/examples/custom-icon.tsx @@ -98,7 +98,7 @@ class CustomIconComponent extends React.Component { onSelect={this.onSelect} onInputKeyDown={this.onKeyDown} notFoundContent="" - allowClear + allowClear={{ clearIcon: getSvg(clearPath) }} placeholder="please select" value={value} mode="combobox" @@ -110,7 +110,6 @@ class CustomIconComponent extends React.Component { } return getSvg(arrowPath); }} - clearIcon={getSvg(clearPath)} removeIcon={getSvg(clearPath)} menuItemSelectedIcon={singleItemIcon} > @@ -185,7 +184,7 @@ class Test extends React.Component { choiceTransitionName="rc-select-selection__choice-zoom" style={{ width: 500 }} mode="multiple" - allowClear + allowClear={{ clearIcon: getSvg(clearPath) }} optionFilterProp="children" optionLabelProp="children" onSelect={this.onSelect} @@ -196,7 +195,6 @@ class Test extends React.Component { tokenSeparators={[' ', ',']} prefix="Foobar" suffixIcon={getSvg(arrowPath)} - clearIcon={getSvg(clearPath)} removeIcon={getSvg(clearPath)} menuItemSelectedIcon={menuItemSelectedIcon} > diff --git a/src/BaseSelect/index.tsx b/src/BaseSelect/index.tsx index a2a15e8c7..68ef0f6fe 100644 --- a/src/BaseSelect/index.tsx +++ b/src/BaseSelect/index.tsx @@ -175,11 +175,6 @@ export interface BaseSelectProps extends BaseSelectPrivateProps, React.AriaAttri allowClear?: boolean | { clearIcon?: RenderNode }; prefix?: React.ReactNode; suffixIcon?: RenderNode; - /** - * Clear all icon - * @deprecated Please use `allowClear` instead - **/ - clearIcon?: RenderNode; /** Selector remove icon */ removeIcon?: RenderNode; @@ -262,7 +257,6 @@ const BaseSelect = React.forwardRef((props, ref) allowClear, prefix, suffixIcon, - clearIcon, // Dropdown OptionList, @@ -733,7 +727,6 @@ const BaseSelect = React.forwardRef((props, ref) onClearMouseDown, displayValues, allowClear, - clearIcon, disabled, mergedSearchValue, mode, diff --git a/src/Select.tsx b/src/Select.tsx index 9ead1bf40..cb075d411 100644 --- a/src/Select.tsx +++ b/src/Select.tsx @@ -70,8 +70,6 @@ export type RawValueType = string | number; export interface LabelInValueType { label: React.ReactNode; value: RawValueType; - /** @deprecated `key` is useless since it should always same as `value` */ - key?: React.Key; } export type DraftValueType = @@ -119,9 +117,6 @@ export interface SelectProps>> Field Names fieldNames?: FieldNames; - // >>> Search - /** @deprecated Use `searchValue` instead */ - inputValue?: string; searchValue?: string; onSearch?: (value: string) => void; autoClearSearchValue?: boolean; @@ -178,7 +173,6 @@ const Select = React.forwardRef search || '', }); @@ -271,7 +265,6 @@ const Select = React.forwardRef, displayValues: DisplayValueType[], allowClear?: boolean | { clearIcon?: RenderNode }, - clearIcon?: RenderNode, disabled: boolean = false, mergedSearchValue?: string, mode?: Mode, ) => { - const mergedClearIcon = React.useMemo(() => { + const clearIcon = React.useMemo(() => { if (typeof allowClear === 'object') { return allowClear.clearIcon; } - if (clearIcon) { - return clearIcon; - } - }, [allowClear, clearIcon]); + }, [allowClear]); const mergedAllowClear = React.useMemo(() => { if ( @@ -39,7 +35,7 @@ export const useAllowClear = ( × diff --git a/src/utils/warningPropsUtil.ts b/src/utils/warningPropsUtil.ts index cd65349bc..7a0fed2ea 100644 --- a/src/utils/warningPropsUtil.ts +++ b/src/utils/warningPropsUtil.ts @@ -28,7 +28,6 @@ function warningProps(props: SelectProps) { autoFocus, labelInValue, value, - inputValue, optionLabelProp, } = props; @@ -149,11 +148,6 @@ function warningProps(props: SelectProps) { }\`.`, ); } - - warning( - inputValue === undefined, - '`inputValue` is deprecated, please use `searchValue` instead.', - ); } } diff --git a/tests/Select.test.tsx b/tests/Select.test.tsx index a37330ddd..7b2d2685d 100644 --- a/tests/Select.test.tsx +++ b/tests/Select.test.tsx @@ -289,7 +289,7 @@ describe('Select.Basic', () => { resetWarned(); const { container: container5 } = render( - x }} value="1"> , @@ -298,7 +298,7 @@ describe('Select.Basic', () => { expect(container5.querySelector('.custom-clear-icon').textContent).toBe('x'); const { container: container6 } = render( - x }}> , @@ -1240,7 +1240,7 @@ describe('Select.Basic', () => { it('does not filter when filterOption value is false', () => { const { container } = testingRender( - , @@ -2330,7 +2330,7 @@ describe('Select.Basic', () => { const renderDemo = (props?: any) => ( - - - ); + render( + , + ); expect(screen.findByText('Foobar')).toBeTruthy(); }); @@ -459,7 +461,7 @@ describe('Select.Multiple', () => { toggleOpen(container); selectItem(container, 0); expect(onChange).toHaveBeenCalledWith( - [{ label: 'Light', value: 'light', key: 'light' }], + [{ label: 'Light', value: 'light' }], [{ label: 'Light', value: 'light', option: 2333 }], ); onChange.mockReset(); @@ -470,8 +472,8 @@ describe('Select.Multiple', () => { selectItem(container, 0); expect(onChange).toHaveBeenCalledWith( [ - { label: 'Light', value: 'light', key: 'light' }, - { label: 'Bamboo', value: 'bamboo', key: 'bamboo' }, + { label: 'Light', value: 'light' }, + { label: 'Bamboo', value: 'bamboo' }, ], [ { label: 'Light', value: 'light', option: 2333 }, diff --git a/tests/Select.test.tsx b/tests/Select.test.tsx index 7b2d2685d..47d430e1d 100644 --- a/tests/Select.test.tsx +++ b/tests/Select.test.tsx @@ -487,7 +487,7 @@ describe('Select.Basic', () => { toggleOpen(container); selectItem(container); expect(handleChange).toHaveBeenCalledWith( - { key: '1', value: '1', label: 'One' }, + { value: '1', label: 'One' }, { children: 'One', key: null, testprop: 'test', value: '1' }, ); }); @@ -508,7 +508,7 @@ describe('Select.Basic', () => { toggleOpen(container); selectItem(container); expect(handleChange).toHaveBeenCalledWith( - { key: '1', label: 'One', value: '1' }, + { label: 'One', value: '1' }, { children: 'One', key: null, testprop: 'test', value: '1' }, ); }); diff --git a/tests/shared/removeSelectedTest.tsx b/tests/shared/removeSelectedTest.tsx index df732f697..62c2bfbde 100644 --- a/tests/shared/removeSelectedTest.tsx +++ b/tests/shared/removeSelectedTest.tsx @@ -50,7 +50,7 @@ export default function removeSelectedTest(mode: any) { const handleChange = jest.fn(); const { container } = render(