I have a component using mat tab from angular material 7.
I want to change the background color of my tabs depending on a boolean value of my typescript variable.
You might not want to set encapsulation: ViewEncapsulation.None, this will make the styling for this component be applied to all other components too.
Instead you can set the color for the tab in your styles.scss like this:
.mat-tab-header{
background-color: #424242;
}
Edited: If you want to change a single tab you can use the aria-label input parameter.
You'll have to add the
encapsulation: ViewEncapsulation.None
And use a specific css selectors like so:
HTML:
<mat-tab-group [color]="colorToggle.value" [backgroundColor]="backgroundColorToggle.value">
<mat-tab label="First" [aria-label]=backgroundColorToggle.value> Content 1 </mat-tab>
<mat-tab label="Second"> Content 2 </mat-tab>
<mat-tab label="Third"> Content 3 </mat-tab>
</mat-tab-group>
CSS:
[aria-label=primary] {
background-color: blue;
}
[aria-label=accent] {
background-color: aqua;
}
You can find example here
If you want for all tabs:
You have a dedicated API for it.
Just use the backgroundColor property like so:
<mat-tab-group [color]="colorToggle.value" [backgroundColor]="backgroundColorToggle.value">
You can find the full example here