Skip to content

Commit 241585e

Browse files
authored
fix(popover): fix the clickoutside bug in the pop-up component (#3899)
1 parent 5bdfec1 commit 241585e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/renderless/src/popover/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,10 @@ export const handleDocumentClick =
183183
const $el = vm.$refs.root
184184
let target = event.target as HTMLElement
185185

186-
// 解决组件在webcomponents中触发document的click事件,但是e.target始终是webcomponents自定义标签,从而引起的判断失效的bug
187-
if (target?.shadowRoot && popperElm) {
186+
// 点击在webcomponents上时,document监听事件的e.target始终是webcomponents自身,所以要判断处理:
187+
// 1. 包含关系:popover使用在乾坤等场景时, popover包含在自定义组件内时, 需要替换target为 真实的 webComponent的内部dom, 再进行判断
188+
// 2. 平级关系:比如页面上有popover 和一个平级关系的自定义dom元素,此时不需要替换target
189+
if (target?.shadowRoot && target.shadowRoot.contains($el) && popperElm) {
188190
target = state.webCompEventTarget as HTMLElement
189191
}
190192

0 commit comments

Comments
 (0)