Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display Vuetify tooltip on disabled button

I am having difficulty displaying a tooltip on a button that is disabled with Vuetify.

I've made sure the tooltip can be displayed when the button is enabled, this works as expected. I think that this question is related, but I'm not well-versed enough to know if this applies to a v-btn. I attempted to create a custom class and add that to the specific v-btn element but I did not have any luck.

Example HTML

<div id="app">   <v-app id="inspire">     <v-container fluid class="text-xs-center">       <v-layout         flex         justify-space-between         row         wrap       >         <v-flex xs12>           <v-btn @click="show = !show">toggle</v-btn>         </v-flex>          <v-flex xs12 class="mt-5">           <v-tooltip v-model="show" top>             <template v-slot:activator="{ on }">               <v-btn disabled icon v-on="on">                 <v-icon color="grey lighten-1">shopping_cart</v-icon>               </v-btn>             </template>             <span>Programmatic tooltip</span>           </v-tooltip>         </v-flex>       </v-layout>     </v-container>   </v-app> </div> 

Example JavaScript

new Vue({   el: '#app',   data () {     return {       show: false     }   } }) 

https://codepen.io/anon/pen/ZNqpOW?editors=1010

I'm expecting that the tooltip can be displayed when hovering over a disabled button. I'm hoping to use this to explain why the button is disabled.

like image 247
ejohnso49 Avatar asked May 30 '19 00:05

ejohnso49


People also ask

How do I add tooltip to disabled button?

By default, tooltips will not be displayed on disabled elements. However, you can enable this behavior by using the following steps: Add a disabled element like the button element into a div whose display style is set to inline-block . Set the pointer event as none for the disabled element (button) through CSS.

How do I add tooltip to Vue?

To create a tooltip using the component approach, we can simply create a button and put the ID in the target attribute. In the code above, we created a button called b-button and gave it a specific ID, tooltip-target-1 .

What is Attrs Vuetify?

$attrs: Stores the attributes setted in the parent component, you can reuse them in a inner component.

How do I change the color of the tooltip in vuetify?

Like many other components in Vuetify, the v-tooltip component comes with the color prop for customizing the color of the tooltip. Using v-model on a v-tooltip allows us to set up a two-way binding between the visibility of the tooltip and a variable. For example, in the code below, we've created a button and a tooltip below it.

How to enable tooltip on disabled-buttons?

It means users cannot focus, hover, or click them to trigger a tooltip (or popover) or any functions. Use the following approaches to enable a tooltip on disabled-buttons. By default tooltips is initialized by selecting the specified element and call the tooltip () method using jQuery.

How do I programmatically control the display of tooltips?

You can also programmatically control the display of tooltips through a v-model. When activated, tooltips display a text label identifying an element, such as a description of its function. Tooltips can wrap any element. A tooltip can be aligned to any of the four sides of the activator element.

What does it mean when a button is disabled?

It means users cannot focus, hover, or click them to trigger a tooltip (or popover) or any functions. Use the following approaches to enable a tooltip on disabled-buttons.


1 Answers

Not sure if this is the absolute best way but I was able to get a tooltip on a disabled button by wrapping it in a div tag:

Codepen

<v-tooltip v-model="show" top>   <template v-slot:activator="{ on }">     <div v-on="on">       <v-btn disabled icon>         <v-icon color="grey lighten-1">shopping_cart</v-icon>       </v-btn>     </div>   </template>   <span>Programmatic tooltip</span> </v-tooltip> 
like image 149
ejohnso49 Avatar answered Sep 18 '22 23:09

ejohnso49