Answer a question

Vuetify buttons keep active state after being clicked. You need to click elsewhere on the screen to remove it. Is there a simple way of adding a timer on returning to inherit state.

I've recently gotten into programming these few last months and just now started using vuetify in my vue project. This issue is something I can solve with unnecessary amounts of code and I'de like to see how you could improve on this.

<v-app-bar app color="#44D0CD" dark>
   <v-app-bar-nav-icon @click.stop="drawer = !drawer"></v-app-bar-nav-icon>
   <v-toolbar-title>Application</v-toolbar-title>
   <v-btn @click="functionOne" light style="">
        <v-icon left>mdi-plus</v-icon>
        Do something
   </v-btn>
   <v-btn @click="functionTwo" light content="Save">
        Do something else
   </v-btn>
</v-app-bar>

I want it to return to the inherit state after a click. Now it stays active on click.

Answers

Turns out that the ::before pseudo element was being set to a higher opacity when the button component was focused ... a simple solution to this is to give the button a custom class and force the pseudo opacity ... here is a demo :

Vue.config.devtools = false
Vue.config.productionTip = false
new Vue({
    el: '#app',
    vuetify: new Vuetify(),
})
.myClass:focus::before {
  opacity: 0 !important;
}
<html>
  <link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet">
<body>
  <div id="app">
     <v-app>
     <v-content>
        <span>with the focus effect:</span> 
        <v-btn>Button</v-btn>
     </v-content>
     <v-content>
        <span>without the focus effect:</span> 
        <v-btn class="myClass">Button</v-btn>
     </v-content>
     </v-app>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.js"></script>
</body>
</html>
Logo

Vue社区为您提供最前沿的新闻资讯和知识内容

更多推荐