Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change color of angular material stepper step icons

In the angular material stepper component, each step is represented by an icon in a circle. The background color of this circle is set to whatever the theme's primary color is. Is it possible to change this color to the theme's accent color? I tried setting color="accent" on both the mat-horizontal-stepper component and each mat-step component, but neither one had any effect and I don't see a color input in the documentation.

like image 822
phelhe Avatar asked Nov 08 '18 17:11

phelhe


People also ask

How do I change the color of my stepper icon?

The color of the stepper bullets can't be changed using any props directly. We can change it by using a theme.

Can we change the color of mat icon?

You can change the color of the icons as per the requirement: Primary . Accent. Warn.

What is steppers in angular?

Angular Material's stepper provides a wizard-like workflow by dividing content into logical steps. Material stepper builds on the foundation of the CDK stepper that is responsible for the logic that drives a stepped workflow.


1 Answers

Of course, you can use your own CSS and customize the background & foreground color. There's no need for ::ng-deep. (/deep/ and ::ng-deep are both currently deprecated)

With a couple of SCSS here's how my stepper looked: I have added SASS snippets needed for customizing the label and icons below:

enter image description here

Completed step & its label:

.mat-step-header .mat-step-icon-state-done, .mat-step-header .mat-step-icon-state-edit {
  background-color: transparent !important;
  color: $success;
  +.mat-step-label{
    color: $success !important;
  }
}

In Progress step & its label:

.mat-step-header .mat-step-icon-selected{
  // background-color: $primary;
  background-color: transparent !important;
  color: $primary;
  +.mat-step-label{
    color: $primary !important;
  }
}

Todo/Default step & its label:

.mat-step-header .mat-step-label{
    color: rgba(0, 0, 0, .54)
}
.mat-step-header .mat-step-icon {
    color: rgba(0, 0, 0, .54);
    background-color: transparent;
}

HTML for overriding default icons: I used font awesome icons to override the defaults:

<mat-horizontal-stepper>
    <!-- Icon overrides. -->
    <ng-template matStepperIcon="edit">
        <i class="fa fa-check-circle"></i>
    </ng-template>
    <ng-template matStepperIcon="active">
        <i class="fa fa-dot-circle-o"></i>
    </ng-template>
    <ng-template matStepperIcon="done">
        <i class="fa fa-dot-circle-o"></i>
    </ng-template>
    <ng-template matStepperIcon="number">
        <i class="fa fa-dot-circle-o"></i>
    </ng-template>
</mat-horizontal-stepper>

Note: All SCSS should be in the global stylesheet and not in the component specific stylesheet. If the styles are present inside the angular component's file it will not be applied due to view encapsulation.

Please define the color variables if needed at the start of the SCSS file as below: Replace the HEX values with your theme colors.

$success:       #35A255 !default;
$primary:       #007CBB !default;
like image 109
Evan MJ Avatar answered Sep 19 '22 12:09

Evan MJ