Skip to content

Commit

Permalink
fix(onClickOutside): put ignore logic on pointerdown event (#2198)
Browse files Browse the repository at this point in the history
  • Loading branch information
GODLiangCY committed Sep 16, 2022
1 parent cd7984c commit a3742d7
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions packages/core/onClickOutside/index.ts
Expand Up @@ -49,27 +49,25 @@ export function onClickOutside<T extends OnClickOutsideOptions>(
window.clearTimeout(fallback)

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

if (!el || el === event.target || composedPath.includes(el) || !shouldListen.value)
if (!el || el === event.target || event.composedPath().includes(el) || !shouldListen.value)
return

if (ignore && ignore.length > 0) {
if (ignore.some((target) => {
const el = unrefElement(target)
return el && (event.target === el || composedPath.includes(el))
}))
return
}

handler(event)
}

const shouldIgnore = (event: PointerEvent) => {
return ignore && ignore.some((target) => {
const el = unrefElement(target)
return el && (event.target === el || event.composedPath().includes(el))
})
}

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

0 comments on commit a3742d7

Please sign in to comment.