Skip to content

Commit cbb386b

Browse files
committed
fix: Tooltip and Popover Fixing centering calculation issues
1 parent e4d7ad7 commit cbb386b

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

packages/bui-utils/src/directionLocationUtil.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ export const getNewDirectionLocation = ({
1515
arrowLocation,
1616
offsetSpacing,
1717
}) => {
18-
const { left: cLeft, right: cRight, top: cTop, bottom: cBottom } = rootOffset;
18+
const {
19+
left: cLeft,
20+
right: cRight,
21+
top: cTop,
22+
bottom: cBottom,
23+
width: cWidth,
24+
height: cHeight,
25+
} = rootOffset;
1926
const { width, height } = tipOffset;
2027
const pgegWidth =
2128
document.documentElement.clientWidth || document.body.clientWidth;
@@ -54,15 +61,17 @@ export const getNewDirectionLocation = ({
5461
const isCenter = arrowLocation === 'center';
5562
// 箭头在中间的情况,是否超过边界
5663
if (isCenter && (isDirectionTop || isDirectionBottom)) {
57-
if (cLeft + width > pgegWidth) {
64+
// cLeft + (cWidth - width) / 2 代表浮层最左侧的坐标
65+
if (cLeft + (cWidth - width) / 2 + width > pgegWidth) {
5866
newArrowLocation = directionCssMap.left;
59-
} else if (cRight - width < 0) {
67+
} else if (cLeft + (cWidth - width) / 2 < 0) {
6068
newArrowLocation = directionCssMap.right;
6169
}
6270
} else if (isCenter && (isDirectionLeft || isDirectionRight)) {
63-
if (cTop + height > pgegHeight) {
71+
// cTop + (cHeight - height) / 2 代表浮层最上侧的坐标
72+
if (cTop + (cHeight - height) / 2 + cHeight > pgegHeight) {
6473
newArrowLocation = directionCssMap.top;
65-
} else if (cBottom - height < 0) {
74+
} else if (cTop + (cHeight - height) / 2 < 0) {
6675
newArrowLocation = directionCssMap.bottom;
6776
}
6877
}

0 commit comments

Comments
 (0)