-
Notifications
You must be signed in to change notification settings - Fork 88
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
Vue 3? #238
Comments
This was the code I used in its entirety in my component:
|
@9mm I haven't cheked Vue 3 yet. I think some changes are needed in order for this directive to work. We should investigate a bit. |
I'm new to vue and sort of this front-end JS madness in general, so I'm not exactly sure how I could help with a PR effectively. With that said I did some digging and I'm assuming the primary reason it's breaking is because vue 3 supports fragments instead of a root node, so it looks lik the https://v3.vuejs.org/guide/custom-directive.html#hook-functions |
Later on down the page:
|
Since vue3 is now released, it would be really nice to get this working. |
We have now the official migrating guide. From a quick glance, it terms of actual code it might just be a matter of updating lifecycle method names to the new ones (since the remaining api is same) and adding the disclaimer mentioned by @9mm when using the directive on custom components that can now have multiple root nodes: for now we can recommend to avoid usage in such scenarios or we would have to loop through the multiple root nodes and bind the directive to each one. At least, in theory 😛 Now in terms of this package structure, I don't how can we make it interoperable with both Vue versions (2.x and 3.x) in a single export, but maybe someone more experienced in OSS can shed a light on the best take. The most common pattern seems to be bump a major version Keen to other options, since code will practically be the same. Something that popped into my head was if we could evaluate cc: @ndelvalle |
Aa far as i could make out, many libraries create a next branch, which holds the new code. The next branch will create pre-releases which can then be uploaded to npm under the @next tag. So someone can then just install v-click-outside@next with npm or yarn. As soon as vue3 becomes the primary release and vue2 is deprecated, the next brach is merged into the master branch. The old code can then be extracted into a new brach like 'vue2' or so. But not too sure if that's the best method. |
Thinking out loud, for a regular library I would certainly go with the Of course, we need to investigate a bit more, sadly I haven't been using vue for a while (Job requires me to do something else) and I was not able to read about vue 3 yet. But if its just an "export issue", we could have a default export and a vue2 version export. So if we can reuse the code the vue2 version will require an explicit import like |
@ndelvalle Interesting idea! This gives me some bad smell though. Having two separate versions in the same package seems a bit overkill. Although v-click-outside ist a tiny library compared to other ones, this still doesn't seem like a clean solution, since now you are shipping two versions of the same functionality for two vue versions doubling the package src size. People might get confused as to what version they should import from the library and might deem it broken. |
Hey! I was also checking in about this, I use v-click-outside and just migrated our app to vue 3! |
any updates? maybe we could do something like this?
|
ok, so if no package is available right now, you can use this
|
@dominykasgithub could you provide PR for this? Add vue3 to dependencies and other important things? |
@crutch12 I'm busy right now migrating from vue2, I'm way behind deadline. Maybe later if issue still persists |
@dominykasgithub was your implementation identical to v-click-outside or a 'light' version which doesn't handle as many edge cases? I'm getting to point where I really need to implement this, but if your version is equal-to or better ill just use that |
For those of you that needs TypeScript support: main.ts
click-outside.ts
|
I'm using a modified version until this issue is officially resolved: https://gist.github.com/jgerigmeyer/87d16753c93762132943a26ea40cc665 |
@jgerigmeyer Yay, that works well! I just had to convert it to JS (via https://www.typescriptlang.org/play) |
Thanks @jgerigmeyer. For anyone else who like me is new to Vue, here's how I got it to work in my Vue 3 app. import { createApp } from 'vue'
import App from './App.vue'
import vClickOutside from './library/v-click-outside'
let app = createApp(App)
app.directive('clickOutside', vClickOutside)
app.mount('#app') And then in my component, I called it like: <template>
<div class="inline-block text-left" v-click-outside="closeDropdown">
</div>
</template> |
Temporarily created this solution for myself based on the comments above https://github.com/andymark-by/vue3-click-outside It works fine for me |
Works fine. TS support would be very nice! |
I just try it today, but getting this error. Any help? |
I've used the solution of andymark-by. It works fine! |
@raphaelbernhart I was try it before found this issue, I got an error also. Maybe that because I use Vite? |
Finally I use another package that working well with Vue 3. I use |
I have been using this but I have a problem. It detects click-outside wrong on router change in a iframe for some reason. When router changes it closes the window. So I found this. It even works with iframes and on route change. click-outside-vue3 |
Someone mentioned this addon in <ndelvalle/v-click-outside#238> <https://github.com/VinceG/vue-click-away>
Someone mentioned this addon in <ndelvalle/v-click-outside#238> <https://github.com/VinceG/vue-click-away>
…d-vue3 feat(#238): isomorphic vue2 and vue3
Hey, does this work with vue 3? I'm trying to use it as a simple directive and it doesn't seem to be firing the log statement. I'm not sure how exactly to debug this though
The text was updated successfully, but these errors were encountered: