Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(design): mouseFollow Tooltip should inherit .ant-tooltip className #849

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/design/src/tooltip/MouseTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ const MouseTooltip: React.FC<MouseTooltipProps> = ({
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,
Expand Down
13 changes: 13 additions & 0 deletions packages/design/src/tooltip/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<Tooltip title="This is prompt text" mouseFollow={true}>
<div id="hello">Hello world!</div>
</Tooltip>
);

const divElement = container.querySelector('#hello');
fireEvent.mouseEnter(divElement!);
await waitFakeTimer();
expect(container.querySelector('.ant-tooltip')).not.toBeNull();
});
});
2 changes: 1 addition & 1 deletion packages/design/src/tooltip/demo/mouse-follow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const App: React.FC = () => {
</Col>
<Col span={12}>
<Tooltip
title="This is prompt text. This is prompt text. This is prompt text. This is prompt text."
title="This is prompt text. This is prompt text. This is prompt text. This is prompt text. This is prompt text."
type={type}
mouseFollow={true}
>
Expand Down
5 changes: 3 additions & 2 deletions packages/design/src/tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>(
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 逻辑
Expand Down Expand Up @@ -108,7 +109,7 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>(
color: typeItem?.color,
...overlayInnerStyle,
}}
className={tooltipCls}
className={mouseTooltipCls}
overlay={overlay}
{...restProps}
>
Expand Down
Loading