From 24b2e14f0758edad1f9ca121942268f7fe49ad59 Mon Sep 17 00:00:00 2001 From: dengfuping Date: Wed, 20 Nov 2024 11:28:58 +0800 Subject: [PATCH] fix(design): mouseFollow Tooltip should inherit `.ant-tooltip` className and style --- packages/design/src/tooltip/MouseTooltip.tsx | 4 ++-- .../design/src/tooltip/__tests__/index.test.tsx | 13 +++++++++++++ packages/design/src/tooltip/demo/mouse-follow.tsx | 2 +- packages/design/src/tooltip/index.tsx | 5 +++-- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/design/src/tooltip/MouseTooltip.tsx b/packages/design/src/tooltip/MouseTooltip.tsx index eec93d26d..4c4f20c64 100644 --- a/packages/design/src/tooltip/MouseTooltip.tsx +++ b/packages/design/src/tooltip/MouseTooltip.tsx @@ -83,10 +83,10 @@ const MouseTooltip: React.FC = ({ boxShadow: token.boxShadowSecondary, borderRadius: token.borderRadius, // @ts-ignore - color: textColor || token.Tooltip.colorTextLightSolid || token.colorTextLightSolid, + color: textColor || token.Tooltip?.colorTextLightSolid || token.colorTextLightSolid, backgroundColor: // @ts-ignore - backgroundColor || token.Tooltip.colorBgSpotlight || token.colorBgSpotlight, + backgroundColor || token.Tooltip?.colorBgSpotlight || token.colorBgSpotlight, left: isOverWidth ? clientX - tooltipWidth - offset : clientX + offset, top: isOverHeight ? clientY - tooltipHeight - offset : clientY + offset, ...restOverlayInnerStyle, diff --git a/packages/design/src/tooltip/__tests__/index.test.tsx b/packages/design/src/tooltip/__tests__/index.test.tsx index 2e0bc37a0..98e51b615 100644 --- a/packages/design/src/tooltip/__tests__/index.test.tsx +++ b/packages/design/src/tooltip/__tests__/index.test.tsx @@ -179,4 +179,17 @@ describe('Tooltip', () => { expect(isTooltipOpen()).toBeFalsy(); expect(container.querySelector('.ant-tooltip-open')).toBeNull(); }); + + it('mouseFollow Tooltip should inherit `.ant-tooltip` className', async () => { + const { container } = render( + +
Hello world!
+
+ ); + + const divElement = container.querySelector('#hello'); + fireEvent.mouseEnter(divElement!); + await waitFakeTimer(); + expect(container.querySelector('.ant-tooltip')).not.toBeNull(); + }); }); diff --git a/packages/design/src/tooltip/demo/mouse-follow.tsx b/packages/design/src/tooltip/demo/mouse-follow.tsx index 5c5362d13..7b5807d3e 100644 --- a/packages/design/src/tooltip/demo/mouse-follow.tsx +++ b/packages/design/src/tooltip/demo/mouse-follow.tsx @@ -38,7 +38,7 @@ const App: React.FC = () => { diff --git a/packages/design/src/tooltip/index.tsx b/packages/design/src/tooltip/index.tsx index c544389a6..3f9ca3981 100644 --- a/packages/design/src/tooltip/index.tsx +++ b/packages/design/src/tooltip/index.tsx @@ -59,7 +59,8 @@ const Tooltip = React.forwardRef( const prefixCls = getPrefixCls('tooltip', customizePrefixCls); const { wrapSSR, hashId } = useStyle(prefixCls); - const tooltipCls = classNames(className, hashId); + const tooltipCls = classNames(className); + const mouseTooltipCls = classNames(prefixCls, className, hashId); const [innerOpen, setInnerOpen] = useState(open ?? visible ?? defaultOpen ?? defaultVisible); // 同步 ant-design noTitle 逻辑 @@ -108,7 +109,7 @@ const Tooltip = React.forwardRef( color: typeItem?.color, ...overlayInnerStyle, }} - className={tooltipCls} + className={mouseTooltipCls} overlay={overlay} {...restProps} >