Skip to content

Commit

Permalink
fix: 修复popover定位问题 (baidu#9796)
Browse files Browse the repository at this point in the history
* fix: 修复popover定位问题

* fix: 修复popover定位问题

---------

Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com>
  • Loading branch information
qkiroc and qkiroc committed Mar 14, 2024
1 parent 42ffae4 commit 45a6e8f
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions packages/amis-core/src/utils/dom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,28 @@ export function calculatePosition(
if (visibleX && visibleY) {
break;
} else if (isAuto && tests.length === 0) {
// 如果是 auto 模式,且最后一个方向都不可见,则直接平移到可见区域
visibleY || (positionTop = window.innerHeight - transformed.height);
visibleX || (positionLeft = window.innerWidth - transformed.width);
// 获取相对定位的父元素位置
let parentElement = overlayNode.offsetParent;
while (
parentElement &&
window.getComputedStyle(parentElement).position === 'static'
) {
parentElement = parentElement.offsetParent;
}
const parentRect = parentElement?.getBoundingClientRect?.();
const parentTransformed = {
x: parentRect?.x || 0,
y: parentRect?.y || 0
};
// 如果是 auto 模式,且最后一个方向都不可见,则直接平移到可见区域,考虑相对定位的父元素位置,保留10px的边距
visibleY ||
(positionTop =
Math.max(10, window.innerHeight - transformed.height) -
parentTransformed.y);
visibleX ||
(positionLeft =
Math.max(10, window.innerWidth - transformed.width) -
parentTransformed.x);
}
}
}
Expand Down

0 comments on commit 45a6e8f

Please sign in to comment.