Skip to content

Commit 454781d

Browse files
crisbetojelbourn
authored andcommitted
fix(autocomplete,select): inconsistent disabled option coloring (#6640)
* Fixes a selected and disabled option in the autocomplete not showing as disabled until it is hovered. * Fixes the disabled and selected options in `md-select` using the theme color, instead of the disabled color. * Fixes the disabled state of an option not being passed down to its checkbox. Fixes #6638.
1 parent 8243b16 commit 454781d

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

src/lib/autocomplete/_autocomplete-theme.scss

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
background: mat-color($background, card);
99
color: mat-color($foreground, text);
1010

11-
.mat-option {
12-
// Selected options in autocompletes should not be gray, but we
13-
// only want to override the background for selected options if
14-
// they are *not* in hover or focus state. This change has to be
15-
// made here because base option styles are shared between the
16-
// autocomplete and the select.
17-
&.mat-selected:not(.mat-active):not(:hover) {
18-
background: mat-color($background, card);
11+
// Selected options in autocompletes should not be gray, but we
12+
// only want to override the background for selected options if
13+
// they are *not* in hover or focus state. This change has to be
14+
// made here because base option styles are shared between the
15+
// autocomplete and the select.
16+
.mat-option.mat-selected:not(.mat-active):not(:hover) {
17+
background: mat-color($background, card);
18+
19+
&:not(.mat-option-disabled) {
1920
color: mat-color($foreground, text);
2021
}
2122
}

src/lib/core/option/_option-theme.scss

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,25 @@
1212
.mat-option {
1313
color: mat-color($foreground, text);
1414

15-
&:hover:not(.mat-option-disabled), &:focus:not(.mat-option-disabled) {
15+
&:hover:not(.mat-option-disabled),
16+
&:focus:not(.mat-option-disabled) {
1617
background: mat-color($background, hover);
1718
}
1819

19-
.mat-primary &.mat-selected {
20+
.mat-primary &.mat-selected:not(.mat-option-disabled) {
2021
color: mat-color($primary);
2122
}
2223

23-
.mat-accent &.mat-selected {
24+
.mat-accent &.mat-selected:not(.mat-option-disabled) {
2425
color: mat-color($accent);
2526
}
2627

27-
.mat-warn &.mat-selected {
28+
.mat-warn &.mat-selected:not(.mat-option-disabled) {
2829
color: mat-color($warn);
2930
}
3031

3132
// In multiple mode there is a checkbox to show that the option is selected.
32-
&.mat-selected:not(.mat-option-multiple) {
33+
&.mat-selected:not(.mat-option-multiple):not(.mat-option-disabled) {
3334
background: mat-color($background, hover);
3435
}
3536

src/lib/core/option/option.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<span [ngSwitch]="_isCompatibilityMode" *ngIf="multiple">
22
<mat-pseudo-checkbox class="mat-option-pseudo-checkbox" *ngSwitchCase="true"
3-
[state]="selected ? 'checked' : ''"></mat-pseudo-checkbox>
3+
[state]="selected ? 'checked' : ''" [disabled]="disabled"></mat-pseudo-checkbox>
44
<md-pseudo-checkbox class="mat-option-pseudo-checkbox" *ngSwitchDefault
5-
[state]="selected ? 'checked' : ''"></md-pseudo-checkbox>
5+
[state]="selected ? 'checked' : ''" [disabled]="disabled"></md-pseudo-checkbox>
66
</span>
77

88
<ng-content></ng-content>

0 commit comments

Comments
 (0)