From 646ca894cd92a5a320a617bc985c8a659b88898a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=B1=AA?= <1844749591@qq.com> Date: Wed, 8 Jan 2025 23:53:15 +0800 Subject: [PATCH] feat: retire deprecated api --- docs/demo/{visible.md => open.md} | 2 +- examples/{visible.tsx => open.tsx} | 6 +++--- src/Cascader.tsx | 23 ++++++----------------- src/utils/warningPropsUtil.ts | 15 +++++---------- tests/index.spec.tsx | 26 ++++++++++---------------- 5 files changed, 25 insertions(+), 47 deletions(-) rename docs/demo/{visible.md => open.md} (54%) rename examples/{visible.tsx => open.tsx} (90%) diff --git a/docs/demo/visible.md b/docs/demo/open.md similarity index 54% rename from docs/demo/visible.md rename to docs/demo/open.md index 8eb8cb6a..1b5608bd 100644 --- a/docs/demo/visible.md +++ b/docs/demo/open.md @@ -5,4 +5,4 @@ nav: path: /demo --- - + diff --git a/examples/visible.tsx b/examples/open.tsx similarity index 90% rename from examples/visible.tsx rename to examples/open.tsx index 775433c8..2080e4de 100644 --- a/examples/visible.tsx +++ b/examples/open.tsx @@ -59,7 +59,7 @@ const addressOptions = [ const Demo = () => { const [value, setValue] = useState([]); - const [popupVisible, setPopupVisible] = useState(false); + const [open, setOpen] = useState(false); const getLabel = () => { return arrayTreeFilter(addressOptions, (o, level) => o.value === value[level]) @@ -69,10 +69,10 @@ const Demo = () => { return ( setPopupVisible(open)} + onPopupVisibleChange={open => setOpen(open)} onChange={value => setValue(value)} > diff --git a/src/Cascader.tsx b/src/Cascader.tsx index c746af10..f6d81382 100644 --- a/src/Cascader.tsx +++ b/src/Cascader.tsx @@ -99,22 +99,18 @@ interface BaseCascaderProps< loadData?: (selectOptions: OptionType[]) => void; // Open - /** @deprecated Use `open` instead */ - popupVisible?: boolean; - /** @deprecated Use `dropdownClassName` instead */ - popupClassName?: string; + /** @deprecated Use `popupClassName` instead */ dropdownClassName?: string; + popupClassName?: string; dropdownMenuColumnStyle?: React.CSSProperties; - /** @deprecated Use `placement` instead */ - popupPlacement?: Placement; placement?: Placement; builtinPlacements?: BuildInPlacements; - /** @deprecated Use `onDropdownVisibleChange` instead */ - onPopupVisibleChange?: (open: boolean) => void; + /** @deprecated Use `onPopupVisibleChange` instead */ onDropdownVisibleChange?: (open: boolean) => void; + onPopupVisibleChange?: (open: boolean) => void; // Icon expandIcon?: React.ReactNode; @@ -209,7 +205,6 @@ const Cascader = React.forwardRef((props, re loadData, // Open - popupVisible, open, popupClassName, @@ -217,7 +212,6 @@ const Cascader = React.forwardRef((props, re dropdownMenuColumnStyle, dropdownStyle: customDropdownStyle, - popupPlacement, placement, onDropdownVisibleChange, @@ -371,13 +365,8 @@ const Cascader = React.forwardRef((props, re onInternalSelect(valueCells); }; - // ============================ Open ============================ - const mergedOpen = open !== undefined ? open : popupVisible; - const mergedDropdownClassName = dropdownClassName || popupClassName; - const mergedPlacement = placement || popupPlacement; - const onInternalDropdownVisibleChange = (nextVisible: boolean) => { onDropdownVisibleChange?.(nextVisible); onPopupVisibleChange?.(nextVisible); @@ -468,9 +457,9 @@ const Cascader = React.forwardRef((props, re OptionList={OptionList} emptyOptions={emptyOptions} // Open - open={mergedOpen} + open={open} dropdownClassName={mergedDropdownClassName} - placement={mergedPlacement} + placement={placement} onDropdownVisibleChange={onInternalDropdownVisibleChange} // Children getRawInputElement={() => children as React.ReactElement} diff --git a/src/utils/warningPropsUtil.ts b/src/utils/warningPropsUtil.ts index 56efed2e..bce4d243 100644 --- a/src/utils/warningPropsUtil.ts +++ b/src/utils/warningPropsUtil.ts @@ -2,20 +2,15 @@ import warning from 'rc-util/lib/warning'; import type { DefaultOptionType, FieldNames, InternalCascaderProps } from '../Cascader'; function warningProps(props: InternalCascaderProps) { - const { onPopupVisibleChange, popupVisible, popupClassName, popupPlacement } = props; + const { onDropdownVisibleChange, dropdownClassName } = props; warning( - !onPopupVisibleChange, - '`onPopupVisibleChange` is deprecated. Please use `onDropdownVisibleChange` instead.', + !onDropdownVisibleChange, + '`onDropdownVisibleChange` is deprecated. Please use `onPopupVisibleChange` instead.', ); - warning(popupVisible === undefined, '`popupVisible` is deprecated. Please use `open` instead.'); warning( - popupClassName === undefined, - '`popupClassName` is deprecated. Please use `dropdownClassName` instead.', - ); - warning( - popupPlacement === undefined, - '`popupPlacement` is deprecated. Please use `placement` instead.', + dropdownClassName === undefined, + '`dropdownClassName` is deprecated. Please use `popupClassName` instead.', ); } diff --git a/tests/index.spec.tsx b/tests/index.spec.tsx index 20e2d67a..7b73af6e 100644 --- a/tests/index.spec.tsx +++ b/tests/index.spec.tsx @@ -514,30 +514,24 @@ describe('Cascader.Basic', () => { expect(wrapper.isOpen()).toBeTruthy(); }); - it('warning popupVisible & onPopupVisibleChange & popupClassName', () => { + it('onDropdownVisibleChange & dropdownClassName', () => { resetWarned(); const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); - const onPopupVisibleChange = jest.fn(); + const onDropdownVisibleChange = jest.fn(); const wrapper = mount( , ); expect(errorSpy).toHaveBeenCalledWith( - 'Warning: `onPopupVisibleChange` is deprecated. Please use `onDropdownVisibleChange` instead.', - ); - expect(errorSpy).toHaveBeenCalledWith( - 'Warning: `popupVisible` is deprecated. Please use `open` instead.', + 'Warning: `onDropdownVisibleChange` is deprecated. Please use `onPopupVisibleChange` instead.', ); expect(errorSpy).toHaveBeenCalledWith( - 'Warning: `popupClassName` is deprecated. Please use `dropdownClassName` instead.', - ); - expect(errorSpy).toHaveBeenCalledWith( - 'Warning: `popupPlacement` is deprecated. Please use `placement` instead.', + 'Warning: `dropdownClassName` is deprecated. Please use `popupClassName` instead.', ); expect(wrapper.exists('.legacy-cls')).toBeTruthy(); @@ -610,7 +604,7 @@ describe('Cascader.Basic', () => { }, ]; const wrapper = mount( - + , ); @@ -622,7 +616,7 @@ describe('Cascader.Basic', () => { const wrapper = mount( (
{menus}