-
-
Notifications
You must be signed in to change notification settings - Fork 7k
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
[Documentation] v-slot:activator="{ on }" #6866
Comments
@YuqiaoS No, it binds slot scope (values that are passed to slot scope), not all data. |
This isn't clear at all. You should add doc to explain what the syntax means. |
But that doesn't tell you that there's the "on" property that the slots pass to the parents that contains some built in listeners that you don't know of. |
Scoped slot passes things that are passed by component |
All v-tooltip slots aren't scoped, you can't get anything from them via this method |
And you don't know what component passes to the slot if you don't read the source code, I agree that there should be explained what data is passed, probably in |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
this I have been digging Vuejs Documentation for a long time and no luck. I don't know what it means. I thought So, what the heck is |
@yuminatwca if you look at at the example you will see that |
Also this can be reported in vue docs repo |
The question is not (I think) what "v-on" means; that's standard Vue. The question is why do I have to pass something called "on" around just to get a tooltip. My component doesn't have anything called "on", so what is the "on" object, why is it needed, is that name part of the API or is it arbitrary, is it useful to me or is it just boilerplate? These are the questions at hand I think. |
According to vuejs documentation, a new syntax has been introduced since 2.4.0+: <!-- object syntax (2.4.0+) -->
<button v-on="{ mousedown: doThis, mouseup: doThat }"></button> But, what is confusing is OK, here is the question: on what? on which event triggered ? |
Accurate. I attempted to implement a date picker yesterday, adhering to the samples provided, and it was breaking on this mysterious "on" construct; only guessing as to why, I decided it must be time to drag my vue and vuetify packages up to latest versions. (Several hours of dependency mazes later) I got it working.
Fwiw, it does evidently only function with |
Up until I have seen this, I was thinking vuetify makes readable codebase ;) |
Far better to write it like this if possible
|
sure but |
Offtopic, but kinda related since this thread is caused by complexity and confusion... Is it super crazy to desire a simple version of tooltips?
Simple text content on hover is, probably, the most common usage of a component. |
Actually if you use the 'v-tooltip' npm module at https://www.npmjs.com/package/v-tooltip, it has even simpler syntax because it's just a directive: <v-icon @click="logOut"
v-tooltip='"Log out"'>
logout
</v-icon> It's not totally material-design but you can style it pretty well. |
@garyo that is a nice example of how a simple tooltip could be declared! So, hopefully, tooltip API will be simpler one day. |
💀 Important to note the example :
uses "click"; it is not same:same |
@elasticdotventures What exactly doesn't work? https://codepen.io/anon/pen/voYNwb |
After reading all the messages above, I still have some confusion 😕 .
So everything is under |
@mcanyucel <v-tooltip>
<template v-slot:activator="{ on: tooltip }">
<v-layout v-on="tooltip">
<v-dialog>
<template v-slot:activator="{ on: dialog }">
<v-btn v-on="dialog">Rate</v-btn>
</template>
</v-dialog>
</v-layout>
</template>
<span>Tooltip text</span>
</v-tooltip> As for why your example is working, consider this example: const on = {
click: () => {
console.log('Outer scope')
}
}
on.click() // --> 'Outer scope'
const inner = () => {
const on = {
click: () => {
console.log('Inner scope')
}
}
on.click()
}
inner() // --> 'Inner scope'
on.click() // --> 'Outer scope' |
Perhaps I don’t understand how to use it. The screen is blank.
Nothing appears on the screen; no button, no press enter, no “click me” just a blank screen.
So I went into my browsers webconsole; by pressing CTRL-SHIFT+J and I saw a big message in red:
vue.js:634 [Vue warn]: Error in beforeCreate hook: "Error: Vuetify is not properly initialized, see https://vuetifyjs.com/getting-started/quick-start#bootstrapping-the-vuetify-object"
Realizing what the problem was – I added
import Vuetify from 'vuetify/lib'
Vue.use(Vuetify);
to the “JS” section; and it worked! So I think the problem is someplace in the codepen template?
/🚀
Sent from Mail for Windows 10
From: Jacek Karczmarczyk
Sent: Thursday, July 18, 2019 3:21 PM
To: vuetifyjs/vuetify
Cc: elasticdotventures; Mention
Subject: Re: [vuetifyjs/vuetify] [Documentation] v-slot:activator="{ on }"(#6866)
@elasticdotventures What exactly doesn't work? https://codepen.io/anon/pen/voYNwb
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
That was 1.x example, here is updated to 2.0 https://codepen.io/jkarczm/pen/oNvBrar |
How can I use this v-on activator (for v-menu) for hover events ?? This is confusing as hell. To click event, this "syntax" vuetify team has choosen works out-of-box.. but when we need hover, this is complicated, when this should not be. |
@aislanmaia you can use the On the larger debate, I can appreciate both sides. On one hand, having an intuitive syntax is fantastic and is part of what makes working with Vue so great; on the other you have syntax that is a little cryptic but elegant and flexible enough for it to be used consistently throughout Vuetify. Ultimately, we live in an ecosystem of abstractions where you don't have to understand everything to accomplish your goal. Stop to consider how many other dependencies you use without understanding what goes on under the hood. Therefore, in my opinion I wouldn't change the syntax. That said, while I don't feel explaining this is necessary for consumption, for the majority of users it is at the very least a repeating pattern that Vuetify is a proponent of. I think we could help users of Vuetify by providing a short breakdown of this somewhere in the documentation. |
There is no example of how to capture the events to do our own actions with this syntax. <v-tooltip bottom>
<template #activator="{ on }">
<v-btn icon v-on="{ ...on, click: openSettings }">
<v-icon>mdi-settings</v-icon>
</v-btn>
</template>
<span>Settings</span>
</v-tooltip> or <v-tooltip bottom>
<template #activator="{ on }">
<v-btn icon v-on="on" @click="openSettings">
<v-icon>mdi-settings</v-icon>
</v-btn>
</template>
<span>Settings</span>
</v-tooltip> But it looks a bit weird. Also, only my second example allows setting modifiers on the |
My 2 cents on all the complains about is that Vue came to save us from the boilerplate that we need to write in React, Angular.... So the selling point of Vue, Vuetify was I think it's time for me to go on my own and write my own beautiful, simple, and powerful framework! I will call it |
For dialogs and menus we still need it BTW i think in other places (lists?) we also use |
how to export the click function to use on my v-model="dialog" and patterns components |
so what is replaces it cus i used in my project and seems not work |
I had to go through this entire thread to find the answer to my question: What is the correct syntax for getting a click event fired on a button that has a v-tooltip. Whew! And I still do not understand why I need any of that "on" stuff. This why I have so little hair left. Thanks to @pdcmoreira for figuring out that you just need to add a @ click. |
@pdcmoreira that's right. I did exactly that, but instead of using a single click I used the whole $listeners in a wrapper fashion way. it results in something like the following:
It makes sense if you think that are both objects:)) |
@Dinuz sure, but that's only if you want to pass all the listeners from parent to child. |
this docs explanation can be short answer for all question about slots and its details : |
I'm using typescript in vscode with vue-3 and vuetify next. The sample code for a dialog on the vuetify site is: <template>
<div class="text-center">
<v-dialog
v-model="dialog"
width="500"
>
<template v-slot:activator="{ on, attrs }">
<v-btn
color="red lighten-2"
dark
v-bind="attrs"
v-on="on"
>
Click Me
</v-btn>
</template>
...
</v-dialog>
</div>
</template> But I kept getting a ts compile error:
Thanks to some of the posts above, I was able to modify the code and get it working. The key line is to change: <template v-slot:activator="{ on, attrs }"> to: <template v-slot:activator="{ isActive: on, props: attrs }"> I'm just paying it forward in case this helps anyone else. Thank you folks on this thread! |
This comment was marked as off-topic.
This comment was marked as off-topic.
@robinzimmermann Look at the examples on https://next.vuetifyjs.com/en/components/dialogs/ |
Thanks @KaelWD! And thank you for not also throwing in "RTFM!" |
Is this still relevant? It seems to be all examples have been replaced with |
https://vuetifyjs.com/en/components/tooltips#usage
So I'm guessing that the activator slot in the component binds the data object from the render function so that its available in the parent scope. The data object contains an
on
property which includes the event listeners.It'd be nice for the doc to provide some pointers to the logic and syntax used. A brief comment in the activator slot description with a link to the below url would be nice.
https://vuejs.org/v2/guide/render-function.html#The-Data-Object-In-Depth
Originally posted by @YuqiaoS in #6823 (comment)
The text was updated successfully, but these errors were encountered: