diff --git a/.gitignore b/.gitignore index e1eb4fbd..2565182b 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ lib es yarn.lock package-lock.json +pnpm-lock.yaml coverage # umi .umi diff --git a/src/Cascader.tsx b/src/Cascader.tsx index 350088c5..778b1ecb 100644 --- a/src/Cascader.tsx +++ b/src/Cascader.tsx @@ -112,9 +112,11 @@ interface BaseCascaderProps< placement?: Placement; builtinPlacements?: BuildInPlacements; - /** @deprecated Use `onDropdownVisibleChange` instead */ + /** @deprecated Use `onOpenChange` instead */ onPopupVisibleChange?: (open: boolean) => void; + /** @deprecated Use `onOpenChange` instead */ onDropdownVisibleChange?: (open: boolean) => void; + onOpenChange?: (open: boolean) => void; // Icon expandIcon?: React.ReactNode; @@ -227,6 +229,7 @@ const Cascader = React.forwardRef((props, re onDropdownVisibleChange, onPopupVisibleChange, + onOpenChange, // Icon expandIcon = '>', @@ -384,6 +387,7 @@ const Cascader = React.forwardRef((props, re const mergedPlacement = placement || popupPlacement; const onInternalDropdownVisibleChange = (nextVisible: boolean) => { + onOpenChange?.(nextVisible) onDropdownVisibleChange?.(nextVisible); onPopupVisibleChange?.(nextVisible); }; diff --git a/src/utils/warningPropsUtil.ts b/src/utils/warningPropsUtil.ts index 56efed2e..51a70d1c 100644 --- a/src/utils/warningPropsUtil.ts +++ b/src/utils/warningPropsUtil.ts @@ -2,11 +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 { onPopupVisibleChange, popupVisible, popupClassName, popupPlacement, onDropdownVisibleChange } = props; warning( !onPopupVisibleChange, - '`onPopupVisibleChange` is deprecated. Please use `onDropdownVisibleChange` instead.', + '`onPopupVisibleChange` is deprecated. Please use `onOpenChange` instead.', + ); + warning( + !onDropdownVisibleChange, + '`onDropdownVisibleChange` is deprecated. Please use `onOpenChange` instead.', ); warning(popupVisible === undefined, '`popupVisible` is deprecated. Please use `open` instead.'); warning( diff --git a/tests/index.spec.tsx b/tests/index.spec.tsx index 558b4b33..bc5efc8d 100644 --- a/tests/index.spec.tsx +++ b/tests/index.spec.tsx @@ -514,21 +514,26 @@ describe('Cascader.Basic', () => { expect(wrapper.isOpen()).toBeTruthy(); }); - it('warning popupVisible & onPopupVisibleChange & popupClassName', () => { + it('warning popupVisible & onPopupVisibleChange & onDropdownVisibleChange & popupClassName & popupPlacement', () => { 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.', + 'Warning: `onPopupVisibleChange` is deprecated. Please use `onOpenChange` instead.', + ); + expect(errorSpy).toHaveBeenCalledWith( + 'Warning: `onDropdownVisibleChange` is deprecated. Please use `onOpenChange` instead.', ); expect(errorSpy).toHaveBeenCalledWith( 'Warning: `popupVisible` is deprecated. Please use `open` instead.',