diff --git a/components/popover/style/index.ts b/components/popover/style/index.ts index 69b273627b..216688e08b 100644 --- a/components/popover/style/index.ts +++ b/components/popover/style/index.ts @@ -88,7 +88,11 @@ const genBaseStyle: GenerateStyle = (token) => { textAlign: 'start', cursor: 'auto', userSelect: 'text', - transformOrigin: `var(--arrow-x, 50%) var(--arrow-y, 50%)`, + + // When use `autoArrow`, origin will follow the arrow position + '--valid-offset-x': 'var(--arrow-offset-horizontal, var(--arrow-x))', + transformOrigin: [`var(--valid-offset-x, 50%)`, `var(--arrow-y, 50%)`].join(' '), + '--antd-arrow-background-color': colorBgElevated, width: 'max-content', maxWidth: '100vw', diff --git a/components/style/placementArrow.ts b/components/style/placementArrow.ts index 38e830416b..ccf677747d 100644 --- a/components/style/placementArrow.ts +++ b/components/style/placementArrow.ts @@ -1,4 +1,5 @@ import type { CSSInterpolation, CSSObject } from '@ant-design/cssinjs'; +import { unit } from '@ant-design/cssinjs'; import type { AliasToken, TokenWithCommonCls } from '../theme/internal'; import type { ArrowToken } from './roundedArrow'; @@ -95,17 +96,25 @@ export default function getArrowStyle< transform: 'translateX(-50%) translateY(100%) rotate(180deg)', }, - [`&-placement-topLeft > ${componentCls}-arrow`]: { - left: { - _skip_check_: true, - value: arrowOffsetHorizontal, + '&-placement-topLeft': { + '--arrow-offset-horizontal': arrowOffsetHorizontal, + + [`> ${componentCls}-arrow`]: { + left: { + _skip_check_: true, + value: arrowOffsetHorizontal, + }, }, }, - [`&-placement-topRight > ${componentCls}-arrow`]: { - right: { - _skip_check_: true, - value: arrowOffsetHorizontal, + '&-placement-topRight': { + '--arrow-offset-horizontal': `calc(100% - ${unit(arrowOffsetHorizontal)})`, + + [`> ${componentCls}-arrow`]: { + right: { + _skip_check_: true, + value: arrowOffsetHorizontal, + }, }, }, }), @@ -129,17 +138,25 @@ export default function getArrowStyle< transform: `translateX(-50%) translateY(-100%)`, }, - [`&-placement-bottomLeft > ${componentCls}-arrow`]: { - left: { - _skip_check_: true, - value: arrowOffsetHorizontal, + '&-placement-bottomLeft': { + '--arrow-offset-horizontal': arrowOffsetHorizontal, + + [`> ${componentCls}-arrow`]: { + left: { + _skip_check_: true, + value: arrowOffsetHorizontal, + }, }, }, - [`&-placement-bottomRight > ${componentCls}-arrow`]: { - right: { - _skip_check_: true, - value: arrowOffsetHorizontal, + '&-placement-bottomRight': { + '--arrow-offset-horizontal': `calc(100% - ${unit(arrowOffsetHorizontal)})`, + + [`> ${componentCls}-arrow`]: { + right: { + _skip_check_: true, + value: arrowOffsetHorizontal, + }, }, }, }), diff --git a/components/tooltip/style/index.ts b/components/tooltip/style/index.ts index 08eaed6995..fcd1a375fc 100644 --- a/components/tooltip/style/index.ts +++ b/components/tooltip/style/index.ts @@ -52,7 +52,11 @@ const genTooltipStyle: GenerateStyle = (token) => { width: 'max-content', maxWidth: tooltipMaxWidth, visibility: 'visible', - transformOrigin: `var(--arrow-x, 50%) var(--arrow-y, 50%)`, + + // When use `autoArrow`, origin will follow the arrow position + '--valid-offset-x': 'var(--arrow-offset-horizontal, var(--arrow-x))', + transformOrigin: [`var(--valid-offset-x, 50%)`, `var(--arrow-y, 50%)`].join(' '), + '&-hidden': { display: 'none', },