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

OnClickoutside: the callback was triggered accidentally when the target is undefined #3465

Closed
7 tasks done
Zephyrrro opened this issue Oct 8, 2023 · 1 comment · Fixed by #3503
Closed
7 tasks done

Comments

@Zephyrrro
Copy link

Describe the bug

In the following case, the target element will render after the focus event triggered, but the click outside callback was also called even the input is ignored.

After seeking the source code, I found the pointerdown event listener may have some problem.

useEventListener(window, 'pointerdown', (e) => {
  const el = unrefElement(target)
  if (el)
    shouldListen = !e.composedPath().includes(el) && !shouldIgnore(e)
}, { passive: true }),

Because the target element is undefined in the first time, so it won't change the value of shouldListen. But in this case, shouldListen should be false

2023-10-08.15.47.47.mov

Reproduction

https://stackblitz.com/edit/vitejs-vite-gvkvun?file=src%2FApp.vue

System Info

System:
    OS: macOS 13.4
    CPU: (10) arm64 Apple M1 Pro
    Memory: 1.72 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node
    npm: 8.19.2 - ~/.nvm/versions/node/v18.12.1/bin/npm
    pnpm: 7.18.2 - /opt/homebrew/bin/pnpm
  Browsers:
    Chrome: 117.0.5938.149
    Safari: 16.5

Used Package Manager

pnpm

Validations

@shawDirectUser
Copy link

meet this bug +1

Doctor-wu added a commit to Doctor-wu/vueuse that referenced this issue Oct 11, 2023
even if the target is falsy, we should care about the ignore options

fix vueuse#3465
Doctor-wu added a commit to Doctor-wu/vueuse that referenced this issue Oct 25, 2023
even if the target is falsy, we should care about the ignore options

fix vueuse#3465
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants