Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To change text-color in mat-list-option

I am using mat-selection-list component in which mat-list-option is displaying a contact list as shown below:

enter image description here

Now the background-color is changing when i click particular contact-name(eg Graeme swan) and background-color is constant until i click another contact , But i want to change the text-color also and the tex-color should be constant until i click new contact.

Hers is the stackblitz link.

like image 432
PGH Avatar asked Oct 20 '25 20:10

PGH


1 Answers

to style your selection in list components as

html

<mat-selection-list #linkList >
  <mat-list-option *ngFor="let link of links;index as i" (selectionChange)="selectionChanged(i)" [class.active]="selectedItem === i">
    <a mat-list-item> <span class="contact-names">{{ link }}</span> </a>
  </mat-list-option>
</mat-selection-list>

add these in ts file

  selectedItem:number = null;

      ....

  selectionChanged(i) {
      selectedItem = i;
  }

add these to css

.mat-list-item.active .contact-names{
  color: red;
}

slackBlitz url

like image 73
Akhi Akl Avatar answered Oct 23 '25 11:10

Akhi Akl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!