1

I use the font-awesome search icon in my project. Actually, I do it in vue.js. The font-awesome-icon is in the input component and I want to change the color of this icon to yellow when the input is active and what's more - also when there are some already typed text in the input.

 <font-awesome-icon :class="isEmpty ? 'white-color' : 'yellow-color'" icon="search" />

Earlier I had css to make this effect, but it didn't handle problem - when some text is already typed, but there is no focus on input. It was like that:

&{
svg {
   color: yellow;
  }
}

1 Answer 1

1

Try doing this

<font-awesome-icon :class="{'white-color' : isEmpty, 'yellow-color': !isEmpty }" icon="search" />

and having the stylings as

.white-color {
  color: white
}
.yellow-color {
  color: yellow
}

ELSE you can use computed property

<font-awesome-icon :style="getColor" icon="search" />

and your computed property should be

computed: {
 getColor() {
   if(this.isEmpty) {
     return {
        color: 'white'
     }
   }
  return {
   color: 'yellow'
  }
 }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.