Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(onClickOutside): put ignore logic on pointerdown event #2198

Merged
merged 2 commits into from Sep 16, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 15 additions & 9 deletions packages/core/onClickOutside/index.ts
Expand Up @@ -54,22 +54,28 @@ export function onClickOutside<T extends OnClickOutsideOptions>(
if (!el || el === event.target || composedPath.includes(el) || !shouldListen.value)
GODLiangCY marked this conversation as resolved.
Show resolved Hide resolved
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): boolean => {
if (!ignore || !ignore.length)
return false

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

return false
}
GODLiangCY marked this conversation as resolved.
Show resolved Hide resolved

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