Skip to content

Commit b0b33b9

Browse files
committed
fix(popup): 优化父级 popup 关闭逻辑,改用可见 overlay 进行碰撞检测
1 parent b5f4e56 commit b0b33b9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/popup/popup.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,12 @@ export default mixins(classPrefixMixins, getAttachConfigMixins('popup')).extend(
345345
// 子元素存在打开的 popup 时,ui 可能重叠,而 dom 节点多是并列关系
346346
// 需要做碰撞检测去阻止父级 popup 关闭
347347
if (this.visibleState > 1) {
348-
const rect = (this.$refs.popper as HTMLElement).getBoundingClientRect();
349-
if (ev.x > rect.x && ev.x < rect.x + rect.width && ev.y > rect.y && ev.y < rect.y + rect.height) return;
348+
// 优先使用实际可见的 overlay 容器进行碰撞检测;
349+
// 在某些场景下(如菜单子菜单弹层),popper 容器可能为 0x0(overlay 采用绝对定位脱离文档流),
350+
// 这会导致用 popper 计算的矩形始终为 0x0,从而误判离开范围,导致父级过早关闭。
351+
const rectTarget = (this.$refs.overlay as HTMLElement) || (this.$refs.popper as HTMLElement);
352+
const rect = rectTarget?.getBoundingClientRect?.();
353+
if (rect && ev.x > rect.x && ev.x < rect.x + rect.width && ev.y > rect.y && ev.y < rect.y + rect.height) return;
350354
}
351355
this.mouseInRange = false;
352356
this.handleClose({});

0 commit comments

Comments
 (0)