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

Prevent default click on outside elements #93

Open
brendan1212 opened this issue Jun 11, 2019 · 4 comments
Open

Prevent default click on outside elements #93

brendan1212 opened this issue Jun 11, 2019 · 4 comments

Comments

@brendan1212
Copy link

Hi there,

I'd love to see this implemented as a feature, if possible. : )

I'm currently using v-click-outside for closing opened dropdowns and popups, but I'd like to prevent the default click on any element in the page that gets clicked while using it this way.

Any suggestions would be great too.

Thanks!

@brendan1212 brendan1212 changed the title Prevent default click on click-outside Prevent default click on outside elements Jun 11, 2019
@ndelvalle
Copy link
Owner

Hi @pachiraDIG this library supports a middleware, the middleware function receives the event as an argument, you can call event.preventDefault() to achieve what you want.

Let me know if this works for you 👍

@brendan1212
Copy link
Author

Hmm... seems as though I can't get the middleware to work. Even the console logs aren't firing. Although, everything is matching up with the codesandbox demo. Using nuxt, so I created a plugin -- which is working because I'm not directly importing the library in the component itself.

Any suggestions?

@ndelvalle
Copy link
Owner

@pachiraDIG take a look at this article maybe we can catch the event at the capturing phase before its bubbling phase.
I think this should be an option and not having this by default, we do not want to stop the event propagation by default.

@719media
Copy link

719media commented Aug 6, 2020

In case anyone else stumbles upon this answer looking for how to prevent default click, there is another wrinkle that tripped me up for a few minutes. This library binds touchstart if the device supports it, otherwise click. So v-outside-click can fire on touchstart, which you attempt to prevent, thinking you're preventing the click...
Anyway, just something to consider when troubleshooting this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants