Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9e598c4

Browse files
Onion-Lantfu
andauthored
fix(onClickOutside): improve cross-browser compatibility (#4185)
Co-authored-by: Anthony Fu <[email protected]>
1 parent 30452c2 commit 9e598c4

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/core/onClickOutside/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,18 @@ export function onClickOutside<T extends OnClickOutsideOptions>(
8686
handler(event)
8787
}
8888

89+
let isProcessingClick = false
90+
8991
const cleanup = [
90-
useEventListener(window, 'click', listener, { passive: true, capture }),
92+
useEventListener(window, 'click', (event: PointerEvent) => {
93+
if (!isProcessingClick) {
94+
isProcessingClick = true
95+
setTimeout(() => {
96+
isProcessingClick = false
97+
}, 0)
98+
listener(event)
99+
}
100+
}, { passive: true, capture }),
91101
useEventListener(window, 'pointerdown', (e) => {
92102
const el = unrefElement(target)
93103
shouldListen = !shouldIgnore(e) && !!(el && !e.composedPath().includes(el))

0 commit comments

Comments
 (0)