Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Material - change color of clicked mat-list-option

Is there a possibility to change the default color of a checked checkbox (mat-pseudo-checkbox-checked):

<mat-selection-list #shoes>
  <mat-list-option *ngFor="let shoe of typesOfShoes">
    {{shoe}}
  </mat-list-option>
</mat-selection-list>

I have tried:

.mat-pseudo-checkbox-checked {
    background-color: #00f;
}

but it has no impact.

like image 450
quma Avatar asked Mar 08 '18 06:03

quma


People also ask

What is the default background color value for the angular material?

The accepted answer works fine, but it uses a hardcoded color value ( background: rgba (0, 139, 139, 0.7) ). This approach will actually break your styles and colors if you decide to switch to another pre-build material theme or use a custom theme (as described in Theming your Angular Material app page).

How to modify the active or selected styles of the mat-list-option?

The mat-list-option has mat-option.mat-active which triggered when option is active and mat-option.mat-selected when an option is selected. Add the following to your CSS to modify the active or selected styles, depends on your need. .mat-option.mat-active { background: blue !important; } .mat-option.mat-selected { background: red !important; }

What is <mat-select> in angular?

The <mat-select> supports 2-way binding to the value property without the need for Angular forms. The <mat-select> also supports all of the form directives from the core FormsModule ( NgModel) and ReactiveFormsModule ( FormControl, FormGroup, etc.)

What is a <mat-list> element?

<mat-list> is a container component that wraps and formats a series of line items. As the base list component, it provides Material Design styling, but no behavior of its own. An <mat-list> element contains a number of <mat-list-item> elements. Use mat-nav-list tags for navigation lists (i.e. lists that have anchor tags).


1 Answers

Just add class="mat-primary" inside <mat-list-option>

<mat-selection-list>
            <mat-list-option class="mat-primary" checkboxPosition="before" *ngFor="let shoe of typesOfShoes">
              {{shoe}}
            </mat-list-option>

Output:

enter image description here

like image 71
vaishali chaudhari Avatar answered Sep 20 '22 16:09

vaishali chaudhari