Skip to content

Commit

Permalink
fix(onClickOutside): fallback to pointerup event if click event n…
Browse files Browse the repository at this point in the history
…ot propagate (#1522)
  • Loading branch information
sibbng committed May 3, 2022
1 parent 23549c3 commit 89c9e53
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/core/onClickOutside/index.ts
Expand Up @@ -37,7 +37,11 @@ export function onClickOutside(

const shouldListen = ref(true)

let fallback: number

const listener = (event: PointerEvent) => {
window.clearTimeout(fallback)

const el = unrefElement(target)
const composedPath = event.composedPath()

Expand All @@ -61,6 +65,9 @@ export function onClickOutside(
const el = unrefElement(target)
shouldListen.value = !!el && !e.composedPath().includes(el)
}, { passive: true }),
useEventListener(window, 'pointerup', (e) => {
fallback = window.setTimeout(() => listener(e), 50)
}, { passive: true }),
]

const stop = () => cleanup.forEach(fn => fn())
Expand Down

0 comments on commit 89c9e53

Please sign in to comment.