Having trouble assigning an active class to the selected button in Vuetify's v-btn-toggle component

In my project, I have implemented a toggle feature using Vuetify's v-button-toggle with three buttons. Each button is supposed to have a different active class that changes when clicked. However, currently the respective active class is not being set when clicking on a button. Can anyone help me identify what I might be missing?

<v-btn-toggle
  v-model="justify"
  borderless
  dense
  group
  class="d-flex flex-column "
>
  <v-btn active-class="dnrSelected" exact>
    <v-icon right class="mr-2">mdi-close</v-icon>
    <span>Do Not Recommend</span>
  </v-btn>
  <v-btn active-class="rSelected">
    <v-icon right class="mr-1">mdi-check</v-icon>
    <span>Recommend</span>
  </v-btn>
  <v-btn active-class="srSelected">
    <v-icon right class="mr-1">mdi-check-all</v-icon>
    <span>Strongly Recommend</span>
  </v-btn>
</v-btn-toggle>

Here are the CSS classes being used:

<style scoped>
  .dnrSelected {
    background-color: #e57373;
  }
  .rSelected {
    background-color: #c5e1a5;
  }
  .srSelected {
    background-color: #81c784;
  }
</style>

An update: The expected class gets added to the button upon click.

<button type="button" class="v-btn srSelected v-btn--active v-btn--contained theme--light v-size--default"><span class="v-btn__content"><i aria-hidden="true" class="v-icon notranslate mr-1 v-icon--right mdi mdi-check-all theme--light"></i> <span>Strongly Recommend</span></span></button>

Another update: There is a default Vuetify class overriding the custom styles applied.

.v-btn-toggle--group > .v-btn.v-btn {
  background-color: transparent !important;
  border-color: transparent;
  margin: 4px;
  min-width: auto;
}

I am looking for suggestions on how to override this default style class.

Answer №1

I gave it a shot on codepen and everything seems to be working smoothly. Here is the link to the codepen

Below you'll find a snippet of the code. For the full version, please refer to the codepen link provided above.

<div id="app">
  <v-app id="inspire">
    <v-card
      flat
      class="py-12"
    >
      <v-card-text>
        <v-row
          align="center"
          justify="center"
        >
          <v-col cols="12">
            <p class="text-center">Multiple</p>
          </v-col>
          <v-btn-toggle
            v-model="toggle_exclusive"

          >
            <v-btn active-class="aa">
              <v-icon>mdi-format-align-left</v-icon>
            </v-btn>
            <v-btn active-class="bb">
              <v-icon>mdi-format-align-center</v-icon>
            </v-btn>
            <v-btn active-class="cc">
              <v-icon>mdi-format-align-right</v-icon>
            </v-btn>
            <v-btn active-class="dd">
              <v-icon>mdi-format-align-justify</v-icon>
            </v-btn>
          </v-btn-toggle>

          <v-col
            cols="12"
            class="text-center"
          >
            Model: {{ toggle_exclusive }}
          </v-col>
        </v-row>
      </v-card-text>
    </v-card>
  </v-app>
</div>

One piece of advice I have is to consider removing the scoped from the style as it may be causing issues with Vuetify's own components.

Answer №2

One solution I've discovered involves specifically targeting elements in the custom CSS by assigning an ID to the containing element as shown below

<v-btn-toggle
 id="btnGroup"
 borderless
 dense
 group
 class="d-flex flex-column"
>

Then, utilize this id to pinpoint target elements like so

#btnGroup .dnrSelected {
  background-color: #ef9a9a !important;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Assigning objects in Vue.js methods

I am working on a Vue component where I need to select a specific value from an array of objects and then copy certain fields from that value into Vue data. <div class="container"> <h4>Add Item</h4> <form @submit.prevent="ad ...

Incorporating a template or component into the Vue.js router.js

If someone can provide me with an answer on how to import templates into route.js in Vue.js, I would greatly appreciate it:) Here is my HTML: <head> <script src="https://cdn.jsdelivr.net/npm/vue"></script> <script src="h ...

Tips for shrinking the circumference of a circle

Currently, I have a circular div that has been styled using CSS animations. My goal is to keep the size of the circle consistent when it moves to the bottom, but reduce its size when it bounces back to the top. I am uncertain if this can be achieved solely ...

The parser for PHP CSS struggles with interpreting semicolons within property values

I encountered an issue while using a function to parse CSS files. The problem arises when the property values contain semicolons, causing it to break. Here's an example snippet from the CSS file: #logo { background-image: url("data:image/png;base ...

When you scroll down, the image and text will appear above the fixed header

As a newcomer to HTML and CSS, I've been working on creating an eCommerce page. The header is fixed, but I've encountered an issue where the image overflows on it when scrolling down the page. If my approach seems odd or unconventional, I would a ...

What is the best way to reduce the spacing between text?

I am trying to figure out how to reduce the spacing between my text so that it aligns like the example below. Take a look at the text "Welcome to my portfolio". Currently, when I run my code, there is a large gap between "Welcome to my" and "Portfolio". ...

Display a pair of distinct items side by side on a webpage

When needing to display information in the format below: Reason : reason number 1 reason number 2 reason number 3 Code : code number Remarks : remark In this scenario, Reason, Code, and Remarks serve as headings enclosed in <s ...

Order the object by the maximum date

Looking to organize the object based on the maximum date for each ID. Certain IDs may have multiple dates associated with them. The example below showcases an object where id:123 has two different dates. In this case, we aim to identify the highest date fo ...

Animate an element when switching routes

Is there a way to smoothly transition an SVG element across a page when the route changes in Vue.js? I've attempted to set up a watcher that triggers an animation based on the route path conditions. Although the transitionName updates correctly, the ...

What is the best way to align a dropdown menu vertically?

Is there a way to center the text vertically alongside the drop-down list so that they are on the same level? <p> <span>Hello World</span><select><option>Hello</option></select> </p> span { font-size: 5 ...

Having trouble with Vue.js not returning HTML elements from methods properly?

I have been attempting to retrieve html elements from a method, and I thought of using v-html for this purpose (not sure if there is a better approach). However, I seem to have encountered an issue with backtick templates and string interpolation. An error ...

Bootstrap dropdown menu fails to adapt to updated navbar height

I recently made a modification to the navbar size on my website, increasing it from 50px to 63px by tweaking a line in the bootstrap.css file. The exact code snippet I utilized for this adjustment is as follows: .navbar { position: relative; min ...

Turn off column wrapping in Bootstrap 4

I'm currently facing a specific scenario: <div class="row no-gutters"> <div class="col"></div> <div class="col col-auto"></div> </div> Essentially, the first column will take up any available space not occ ...

Struggling to get the onHover effect working with the Grid item component in MaterialUI

I'm currently working on a Grid layout with nested Grid components, but I've run into an issue where applying inline styles to the Grid item component isn't working as expected. As a newcomer to MaterialUI in ReactJS, I could really use some ...

Tips for creating a dynamic animation of a ball following a curved trajectory with CSS3

Looking to create a cool animation where a ball moves along a curved path? Struggling to figure out how to do it with CSS3 since there's no built-in path animation feature? Wondering if it's possible to animate a ball on a curved background? Ca ...

Tips for arranging elements in proper order following a rotation

Having trouble aligning rotated divs? Let's say we rotate .straight by 30deg, and now we want to find the new offset coordinates of its bottom right corner. This way, we can perfectly match up the bottom left corners of .curve with this new coordinate ...

Complete page browsing experience

Interactive Vertical Full Page Slider Concept I am interested in developing an interactive full-page slider that moves vertically instead of scrolling. This project would allow users to slide between page divs using the mousewheel. I am pursuing this ide ...

When switching between classes, it is not possible to apply a different value to the same CSS property

I am currently working on a project that involves toggling a class on a ul tag with an id of sideNav using JavaScript. In this scenario, I have set the left attribute of the id to 0, while the same attribute in the class has a value of -100%. After sever ...

Tips for transferring an item to a different location using JavaScript and CSS animation

I am attempting to implement a coin collection animation into the cart using only JavaScript and Vue.js. I decided to use raw JavaScript for this purpose after initially following a tutorial on W3schools at https://www.w3schools.com/js/tryit.asp?filename=t ...

Configuring universal sass variables within a vue application

After following the instructions in the documentation to create a vue.config.js file and set some global sass variables, I encountered an issue where the variables were undefined when accessed in a component. Manually adding the import statement in the com ...