5
votes

As you can see from the offical docs of vuetify, the labels for switches have their own pre defined color. How can i override them to get black text? I am passing the switch as a prop from a global component called form structure into another component that i have named "Primary"

https://vuetifyjs.com/en/components/selection-controls

<v-switch v-if="externalSwitch" model="switch2":label="externalSwitchLabel"> 
</v-switch>

<v-layout v-for="info in information" :key="info.title">
  <v-flex>
    <form-structure :externalSwitchLabel="`${info.title}`" 
      :externalSwitch="true" :hasSubTitle="true" :subTitle="`${info.status}`" 
      :script="`${info.script}`">
    </form-structure>
  </v-flex>
</v-layout>

My array looks like this:

information : [
  {title: "Something1", status:"active", script: "Hello"},
  {title: "Something2", status:"in Progress", script: "Ciao" }
]

My Css looks like this:

<style scoped>
.v-label.theme--light {
  color: black
}
</style>
5
Hello again please provide some tried code - Boussadjra Brahim
Hello, I just updated the question and added more details. - user9996891
Have you tried the following? .v-label.theme--light{ color: black !important; } - Max Martynov
yeah i tried it, it didn't work. It only works if i take out scoped from my style but then it changes every label on every other page and on every text field as well. - user9996891
See this answer to understand why your css is not working stackoverflow.com/a/50985784/1981247 - Traxo

5 Answers

4
votes

I tried the slot approach and it worked for me:

<v-switch>
   <template v-slot:label>
      <span class="input__label">Label text</span>
   </template>
</v-switch>

CSS looks like this:

.input__label {
   color: black;
}
1
votes

You could use color prop by giving it rgb or hexadecimal value as follows :

new Vue({
  el: '#app',
  data () {
    return {
   
      switch1: true,
      switch2: true
    }
  }
})
.v-input__slot .v-label{
color: black!important
}
<script src="https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.css">
<div id="app">
  <v-app id="inspire">
    <v-container fluid px-0>
     
      <v-switch
        :label="`Switch 1: ${switch1.toString()}`"
        v-model="switch1"
                color="#f45525"
      ></v-switch>
       <v-switch
        :label="`Switch 2: ${switch2.toString()}`"
        v-model="switch2"
                color="rgb(0,150,45)"
      ></v-switch>
    </v-container>
  </v-app>
</div>
1
votes

If you don't want to override the default style for the label, you can pass in a slot to v-switch with your desired styled element.

Example:

<v-switch v-model="enableScreenshot" label="Enable Screenshot">
   <template v-slot:label>
      <span class="v-label-white">Enable Screenshot</span>
   </template>
</v-switch>

Then your style:

.v-label-white {
  color: white;
  font-weight: bolder
}
0
votes

You only need to remove scoped from style:

<style>
.v-label.theme--light{
  color: black
}
</style>

This means that the style will be applied globally in the application.

0
votes

Try this.

.v-input--is-label-active label {
    color: red !important;
}