LeO
LeO

Reputation: 5258

Theming in Angular 6 (and 7) for Mat-button-toggle

I found the wonderful link how to customize the Material toggle button. I succeed to set the background-color and the font-weight the way I want with

@import '~@angular/material/theming';

@include mat-core();

$app-primary: mat-palette($mat-indigo);
$app-accent:  mat-palette($mat-pink, A200, A100, A400);

$app-theme: mat-light-theme($app-primary, $app-accent);

@mixin mix-app-theme($app-theme) {
  $primary: map-get($app-theme, primary);
  $accent: map-get($app-theme, accent);

.mat-button-toggle-checked {
    background-color: mat-color($primary);
    font-weight: bold;
    color:mat-color($primary); // <=== does not work!!!
  }
}

// Include the mixin
@include mix-app-theme($app-theme);

But somehow the font itself remains on black - which is not the default color when using color="primary".

Any idea how to include the fore-color as well - properly?

Upvotes: 2

Views: 5949

Answers (3)

Manas Sahu
Manas Sahu

Reputation: 907

For newer versions of Material you will also need to include this class .mat-button-toggle-appearance-standard

.mat-button-toggle-appearance-standard .mat-button-toggle-label-content {
    line-height: 0px;
    padding: 4px 7px;
}
.mat-button-toggle{
    background-color: #B2B2B2;
    color: #ffffff;
}
.mat-button-toggle-checked {
    background-color: #48A808;
    color: #ffffff;
}

Upvotes: 1

LeO
LeO

Reputation: 5258

Thanx to @Akhi Akl I and looking into the themes I found the following solution for mat-button-toggle in color primary

@import '~@angular/material/theming';

@include mat-core();

$app-primary: mat-palette($mat-indigo);
$app-accent:  mat-palette($mat-pink, A200, A100, A400);

$app-theme: mat-light-theme($app-primary, $app-accent);

@mixin mix-app-theme($app-theme) {
  $primary: map-get($app-theme, primary);

  .mat-button-toggle-checked {
    background-color: mat-color($primary);
    font-weight: bold;

    .mat-button-toggle-label-content{
        color: $light-primary-text;
    }
  }
}

// Include the mixin
@include mix-app-theme($app-theme);

Upvotes: 6

Akhi Akl
Akhi Akl

Reputation: 3941

try using this

.mat-button-toggle-label-content{
   color:mat-color($primary)
}

if you want change color of checked button only try this

.mat-button-toggle-checked {
   .mat-button-toggle-label-content{
       color:mat-color($primary)
    }
}

Upvotes: 4

Related Questions