fix: Tooltip min width to resolve arrow pos (#51904)
Some checks are pending
Publish Any Commit / build (push) Waiting to run
🔀 Sync mirror to Gitee / mirror (push) Waiting to run
✅ test / lint (push) Waiting to run
✅ test / test-react-legacy (16, 1/2) (push) Waiting to run
✅ test / test-react-legacy (16, 2/2) (push) Waiting to run
✅ test / test-react-legacy (17, 1/2) (push) Waiting to run
✅ test / test-react-legacy (17, 2/2) (push) Waiting to run
✅ test / test-node (push) Waiting to run
✅ test / test-react-latest (dom, 1/2) (push) Waiting to run
✅ test / test-react-latest (dom, 2/2) (push) Waiting to run
✅ test / test-react-latest-dist (dist, 1/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist, 2/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist-min, 1/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist-min, 2/2) (push) Blocked by required conditions
✅ test / test-coverage (push) Blocked by required conditions
✅ test / build (push) Waiting to run
✅ test / test lib/es module (es, 1/2) (push) Waiting to run
✅ test / test lib/es module (es, 2/2) (push) Waiting to run
✅ test / test lib/es module (lib, 1/2) (push) Waiting to run
✅ test / test lib/es module (lib, 2/2) (push) Waiting to run
👁️ Visual Regression Persist Start / test image (push) Waiting to run

* fix: tooltip arrow min width

* test: update snapshot

* fix: multiple width

* demo: update demo
This commit is contained in:
二货爱吃白萝卜 2024-12-05 14:51:56 +08:00 committed by GitHub
parent d4d6492369
commit d2b311f27a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 43 additions and 10 deletions

View File

@ -1,15 +1,26 @@
import React from 'react';
import { Button, Tooltip } from 'antd';
import { Button, Flex, Tooltip } from 'antd';
const zeroWidthEle = <div />;
const App: React.FC = () => (
<Tooltip
open
title="Thanks for using antd. Have a nice day !"
arrow={{ pointAtCenter: true }}
placement="topLeft"
>
<Button>Point at center</Button>
</Tooltip>
<Flex vertical gap={72} align="flex-start">
<span />
<Tooltip
open
title="Thanks for using antd. Have a nice day !"
arrow={{ pointAtCenter: true }}
placement="topLeft"
>
<Button>Point at center</Button>
</Tooltip>
<Tooltip open title={zeroWidthEle} placement="topLeft">
<Button>Min Width</Button>
</Tooltip>
<Tooltip open title={zeroWidthEle} placement="top">
<Button>Min Width</Button>
</Tooltip>
</Flex>
);
export default App;

View File

@ -30,6 +30,7 @@ interface TooltipToken extends FullToken<'Tooltip'> {
const genTooltipStyle: GenerateStyle<TooltipToken> = (token) => {
const {
calc,
componentCls, // ant-tooltip
tooltipMaxWidth,
tooltipColor,
@ -40,8 +41,19 @@ const genTooltipStyle: GenerateStyle<TooltipToken> = (token) => {
boxShadowSecondary,
paddingSM,
paddingXS,
arrowOffsetHorizontal,
sizePopupArrow,
} = token;
// arrowOffsetHorizontal + arrowWidth + borderRadius
const edgeAlignMinWidth = calc(tooltipBorderRadius)
.add(sizePopupArrow)
.add(arrowOffsetHorizontal)
.equal();
// borderRadius * 2 + arrowWidth
const centerAlignMinWidth = calc(tooltipBorderRadius).mul(2).add(sizePopupArrow).equal();
return [
{
[componentCls]: {
@ -65,7 +77,7 @@ const genTooltipStyle: GenerateStyle<TooltipToken> = (token) => {
// Wrapper for the tooltip content
[`${componentCls}-inner`]: {
minWidth: '1em',
minWidth: centerAlignMinWidth,
minHeight: controlHeight,
padding: `${unit(token.calc(paddingSM).div(2).equal())} ${unit(paddingXS)}`,
color: tooltipColor,
@ -78,6 +90,16 @@ const genTooltipStyle: GenerateStyle<TooltipToken> = (token) => {
boxSizing: 'border-box',
},
// Align placement should have another min width
[[
`&-placement-topLeft`,
`&-placement-topRight`,
`&-placement-bottomLeft`,
`&-placement-bottomRight`,
].join(',')]: {
minWidth: edgeAlignMinWidth,
},
// Limit left and right placement radius
[[
`&-placement-left`,