Skip to content

Commit

Permalink
fix(onClickOutside): improve cross-browser compatibility (vueuse#4185)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <github@antfu.me>
  • Loading branch information
Onion-L and antfu authored Sep 12, 2024
1 parent 30452c2 commit 9e598c4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/core/onClickOutside/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,18 @@ export function onClickOutside<T extends OnClickOutsideOptions>(
handler(event)
}

let isProcessingClick = false

const cleanup = [
useEventListener(window, 'click', listener, { passive: true, capture }),
useEventListener(window, 'click', (event: PointerEvent) => {
if (!isProcessingClick) {
isProcessingClick = true
setTimeout(() => {
isProcessingClick = false
}, 0)
listener(event)
}
}, { passive: true, capture }),
useEventListener(window, 'pointerdown', (e) => {
const el = unrefElement(target)
shouldListen = !shouldIgnore(e) && !!(el && !e.composedPath().includes(el))
Expand Down

0 comments on commit 9e598c4

Please sign in to comment.