How can I make it so that the out of focus styles don't apply when there is text inside the mat-input while simultaneously being out of focus?
I want to keep these styles when out of focus and with text:
But right now this is what I'm getting when out of focus and with text:
Also, this is how the field looks when there is no text and out of focus:
My current styles:
.mat-form-field-appearance-outline .mat-form-field-outline {
background-color: #FFFFFF66;
border-radius: 10em;
color: transparent;
opacity: 0.5;
}
.mat-form-field-appearance-outline.mat-focused .mat-form-field-outline-thick {
color: white;
background-color: transparent;
}
Thank you in advance.



I see in the comments that you have noticed Angular removes the
mat-focusedclass, so applying it to themat-form-fielddirectly will not work. However, we should be able to apply classes to a wrapper container that will match the 'focused' style.div.mat-form-field-outlinehas 'focused' rules when nested in an element withmat-form-field-appearance-outlineandmat-focusedclassesThe
mat-labelelement has 'focused' rules when nested in an element withmat-form-fieldandmat-focusedclasses.So we can provide the
mat-form-field-appearance-outlineandmat-form-fieldclasses to a container and toggle themat-focusedclass based on the form field value.https://stackblitz.com/edit/angular-ckvs4z?file=src/app/form-field-appearance-example.html