fakhfakh emna
fakhfakh emna

Reputation: 73

Vuetify : How to set selected item background color in v-select

I have this v-select and I want to change the background color of the selected item to 'white' and keep the text color in blue

enter image description here

I have tried to add item-color attribute to my v-select but it changes the background and the text color so we can't see the text anymore. I also tried to add a scoped style like this but it doesn't work :(

.v-list-item--active {
  background-color: white !important;
}

Any one can help ?

Upvotes: 0

Views: 5396

Answers (4)

Vigan Dika
Vigan Dika

Reputation: 66

For me, styling the item inside the v-select works only if I remove scoped from the style block:

<style>
  .v-list-item--active {
     background-color: white;
  }
</style>

Upvotes: 0

Mohsen
Mohsen

Reputation: 4235

Try this one:

.v-list .v-list-item--link:before{
  background-color: #fff !important;
}

Here is codepen simple.

Upvotes: 0

Don't really know if its the effect that you're looking for but to preserve the dark mode you should instead remove the opacity from the active element

.v-list-item--active::before { opacity: 0 }

Keep in mind that this rule applies to all list items active.

If you want to do it on a single select or only on selects, you should target the elements that you want


/* Examples */

.v-select .v-list-item--active::before { opacity: 0 }
.v-select--is-multi .v-list-item--active::before { opacity: 0 }
.my-pale-select  .v-list-item--active::before { opacity: 0 }

Upvotes: 0

Jay Fridge
Jay Fridge

Reputation: 1057

I achieved this by using the item prop of the v-select and placing a v-list-item inside.

<v-select
  :items="[1,2,3]"
  multiple
>
  <template v-slot:item="{item, on, attrs}">
    <v-list-item v-on="on">
      <v-list-item-action>
        <v-simple-checkbox
          :value="attrs.inputValue"
          v-on="on"
          color="primary"
          :ripple="false"
        ></v-simple-checkbox>
      </v-list-item-action>
      <v-list-item-content>
        <v-list-item-title :class="attrs.inputValue ? 'primary--text' : ''">
          {{ item }}
        </v-list-item-title>
      </v-list-item-content>
    </v-list-item>
  </template>
</v-select>

attrs.inputValue holds the selected state of the item which I use to set the primary--text class on the v-list-item-title.

FYI: The :ripple="false" attribute on the v-simple-checkbox is necessary to prevent errors in the console, because there is an open bug with the ripple directive on this component.

Upvotes: 1

Related Questions