mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-05 18:17:58 +08:00
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
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:
parent
d4d6492369
commit
d2b311f27a
@ -1,15 +1,26 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Button, Tooltip } from 'antd';
|
import { Button, Flex, Tooltip } from 'antd';
|
||||||
|
|
||||||
|
const zeroWidthEle = <div />;
|
||||||
|
|
||||||
const App: React.FC = () => (
|
const App: React.FC = () => (
|
||||||
<Tooltip
|
<Flex vertical gap={72} align="flex-start">
|
||||||
open
|
<span />
|
||||||
title="Thanks for using antd. Have a nice day !"
|
<Tooltip
|
||||||
arrow={{ pointAtCenter: true }}
|
open
|
||||||
placement="topLeft"
|
title="Thanks for using antd. Have a nice day !"
|
||||||
>
|
arrow={{ pointAtCenter: true }}
|
||||||
<Button>Point at center</Button>
|
placement="topLeft"
|
||||||
</Tooltip>
|
>
|
||||||
|
<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;
|
export default App;
|
||||||
|
@ -30,6 +30,7 @@ interface TooltipToken extends FullToken<'Tooltip'> {
|
|||||||
|
|
||||||
const genTooltipStyle: GenerateStyle<TooltipToken> = (token) => {
|
const genTooltipStyle: GenerateStyle<TooltipToken> = (token) => {
|
||||||
const {
|
const {
|
||||||
|
calc,
|
||||||
componentCls, // ant-tooltip
|
componentCls, // ant-tooltip
|
||||||
tooltipMaxWidth,
|
tooltipMaxWidth,
|
||||||
tooltipColor,
|
tooltipColor,
|
||||||
@ -40,8 +41,19 @@ const genTooltipStyle: GenerateStyle<TooltipToken> = (token) => {
|
|||||||
boxShadowSecondary,
|
boxShadowSecondary,
|
||||||
paddingSM,
|
paddingSM,
|
||||||
paddingXS,
|
paddingXS,
|
||||||
|
arrowOffsetHorizontal,
|
||||||
|
sizePopupArrow,
|
||||||
} = token;
|
} = 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 [
|
return [
|
||||||
{
|
{
|
||||||
[componentCls]: {
|
[componentCls]: {
|
||||||
@ -65,7 +77,7 @@ const genTooltipStyle: GenerateStyle<TooltipToken> = (token) => {
|
|||||||
|
|
||||||
// Wrapper for the tooltip content
|
// Wrapper for the tooltip content
|
||||||
[`${componentCls}-inner`]: {
|
[`${componentCls}-inner`]: {
|
||||||
minWidth: '1em',
|
minWidth: centerAlignMinWidth,
|
||||||
minHeight: controlHeight,
|
minHeight: controlHeight,
|
||||||
padding: `${unit(token.calc(paddingSM).div(2).equal())} ${unit(paddingXS)}`,
|
padding: `${unit(token.calc(paddingSM).div(2).equal())} ${unit(paddingXS)}`,
|
||||||
color: tooltipColor,
|
color: tooltipColor,
|
||||||
@ -78,6 +90,16 @@ const genTooltipStyle: GenerateStyle<TooltipToken> = (token) => {
|
|||||||
boxSizing: 'border-box',
|
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
|
// Limit left and right placement radius
|
||||||
[[
|
[[
|
||||||
`&-placement-left`,
|
`&-placement-left`,
|
||||||
|
Loading…
Reference in New Issue
Block a user