From db1da678727838cc58c21ac4963ee265743a6f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=B1=AA?= <1844749591@qq.com> Date: Wed, 26 Mar 2025 15:52:43 +0800 Subject: [PATCH 1/3] refacto: rename visibility change props for clarity --- .gitignore | 3 ++- src/Tooltip.tsx | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 93e1cbd..e466542 100644 --- a/.gitignore +++ b/.gitignore @@ -41,4 +41,5 @@ package-lock.json .dumi/tmp .dumi/tmp-production -bun.lockb \ No newline at end of file +bun.lockb +.vscode/ \ No newline at end of file diff --git a/src/Tooltip.tsx b/src/Tooltip.tsx index 5092c6f..f8f3444 100644 --- a/src/Tooltip.tsx +++ b/src/Tooltip.tsx @@ -27,8 +27,8 @@ export interface TooltipProps placement?: string; /** Config popup motion */ motion?: TriggerProps['popupMotion']; - onVisibleChange?: (visible: boolean) => void; - afterVisibleChange?: (visible: boolean) => void; + onOpenChange?: (visible: boolean) => void; + afterOpenChange?: (visible: boolean) => void; overlay: (() => React.ReactNode) | React.ReactNode; /** @deprecated Please use `styles={{ root: {} }}` */ overlayStyle?: React.CSSProperties; @@ -68,8 +68,8 @@ const Tooltip = (props: TooltipProps, ref: React.Ref) => { overlayStyle, prefixCls = 'rc-tooltip', children, - onVisibleChange, - afterVisibleChange, + onOpenChange, + afterOpenChange, motion, placement = 'right', align = {}, @@ -131,8 +131,8 @@ const Tooltip = (props: TooltipProps, ref: React.Ref) => { ref={triggerRef} popupAlign={align} getPopupContainer={getTooltipContainer} - onPopupVisibleChange={onVisibleChange} - afterPopupVisibleChange={afterVisibleChange} + onOpenChange={onOpenChange} + afterOpenChange={afterOpenChange} popupMotion={motion} defaultPopupVisible={defaultVisible} autoDestroy={destroyTooltipOnHide} From b1e392a0679069175cd9561bda5da314b328d7c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=B1=AA?= <1844749591@qq.com> Date: Wed, 26 Mar 2025 16:21:46 +0800 Subject: [PATCH 2/3] refactor: update Tooltip component to use 'open' prop for visibility control --- src/Tooltip.tsx | 15 ++++++--------- tests/index.test.tsx | 4 ++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Tooltip.tsx b/src/Tooltip.tsx index f8f3444..061b29b 100644 --- a/src/Tooltip.tsx +++ b/src/Tooltip.tsx @@ -23,12 +23,12 @@ export interface TooltipProps > { trigger?: ActionType | ActionType[]; defaultVisible?: boolean; - visible?: boolean; + open?: boolean; placement?: string; /** Config popup motion */ motion?: TriggerProps['popupMotion']; - onOpenChange?: (visible: boolean) => void; - afterOpenChange?: (visible: boolean) => void; + onOpenChange?: (open: boolean) => void; + afterOpenChange?: (open: boolean) => void; overlay: (() => React.ReactNode) | React.ReactNode; /** @deprecated Please use `styles={{ root: {} }}` */ overlayStyle?: React.CSSProperties; @@ -83,6 +83,7 @@ const Tooltip = (props: TooltipProps, ref: React.Ref) => { showArrow = true, classNames: tooltipClassNames, styles: tooltipStyles, + open, ...restProps } = props; @@ -91,11 +92,6 @@ const Tooltip = (props: TooltipProps, ref: React.Ref) => { useImperativeHandle(ref, () => triggerRef.current); - const extraProps: Partial = { ...restProps }; - if ('visible' in props) { - extraProps.popupVisible = props.visible; - } - const getPopupElement = () => ( ) => { popupStyle={{ ...overlayStyle, ...tooltipStyles?.root }} mouseEnterDelay={mouseEnterDelay} arrow={showArrow} - {...extraProps} + popupVisible={open} + {...restProps} > {getChildren()} diff --git a/tests/index.test.tsx b/tests/index.test.tsx index 7436ab8..f52e24a 100644 --- a/tests/index.test.tsx +++ b/tests/index.test.tsx @@ -222,7 +222,7 @@ describe('rc-tooltip', () => { const App = () => { const [open, setOpen] = React.useState(false); return ( - Tooltip content} visible={open}> + Tooltip content} open={open}>
{ @@ -263,7 +263,7 @@ describe('rc-tooltip', () => { }; const { container } = render( - } styles={customStyles} visible> + } styles={customStyles} open>