I’m currently working with Angular Material version 15.2.9 and encountering an issue where the disabled state of the mat-datepicker-toggle
icon remains black, whereas the enabled state correctly shows as grey. I’ve attempted to override the CSS to change the icon color, it successfully applies to the enabled state but seems to have no effect on the disabled state. For instance, even if I set the icon color to red, the disabled icon still appears black.
<mat-form-field appearance="outline" class="w-100 date-input">
<input
[id]="'startDate' + idx"
[formControl]="formManager.getStartDate(idx)"
placeholder="MM/DD/YYYY"
matInput
readonly
[matDatepicker]="picker"
(click)="picker.open()"/>
<mat-datepicker-toggle disabled matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
.mat-datepicker-toggle.mat-datepicker-toggle {
color: red !important;
}
.mat-datepicker-toggle[disabled] .mat-icon,
.mat-datepicker-toggle.mat-datepicker-toggle-disabled .mat-icon {
color: red !important;
}
Has anyone faced a similar issue or can provide insight on how to correctly override the color for the disabled state? Any suggestions or solutions would be greatly appreciated.
2
Answers
It seems that the problem is related to the Angular version upgrade that was done several months ago. The solution in my case was to include both core and legacy components in the Material theming. Previously, only the legacy components were included, but I added the core components as well.
This CSS will change the color of disabled icon in date picker
Stackblitz Demo