Skip to content

Commit d4a9624

Browse files
authored
fix(material-experimental/mdc-form-field): native select option blending in with background on dark themes (#19232)
On dark themes the `color` of the native `select` inside of an MDC-based form field is usually set to some shade of white. The problem is that the color of the native `select` dropdown preserves its white background, making the text invisible. These changes make it so that the options always use a dark text color.
1 parent 1bec9dc commit d4a9624

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/material-experimental/mdc-form-field/_form-field-native-select.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@import '../../material/core/theming/theming';
12
@import '../../cdk/a11y/a11y';
23

34
// Width of the Material Design form-field select arrow.
@@ -88,3 +89,22 @@ $mat-form-field-select-horizontal-end-padding: $mat-form-field-select-arrow-widt
8889
}
8990
}
9091
}
92+
93+
@mixin _mat-form-field-native-select-theme($theme) {
94+
select.mat-mdc-input-element {
95+
// On dark themes we set the native `select` color to some shade of white,
96+
// however the color propagates to all of the `option` elements, which are
97+
// always on a white background inside the dropdown, causing them to blend in.
98+
// Since we can't change background of the dropdown, we need to explicitly
99+
// reset the color of the options to something dark.
100+
@if (map-get($theme, is-dark)) {
101+
option {
102+
color: $dark-primary-text;
103+
}
104+
105+
option:disabled {
106+
color: $dark-disabled-text;
107+
}
108+
}
109+
}
110+
}

src/material-experimental/mdc-form-field/_form-field-theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@import '../mdc-helpers/mdc-helpers';
66
@import 'form-field-subscript';
77
@import 'form-field-focus-overlay';
8+
@import 'form-field-native-select';
89
@import 'mdc-text-field-theme-variable-refresh';
910

1011
// Mixin that overwrites the default MDC text-field color styles to be based on
@@ -40,6 +41,7 @@
4041
@include mdc-line-ripple-core-styles($query: $mat-theme-styles-query);
4142
@include _mat-form-field-subscript-theme();
4243
@include _mat-form-field-focus-overlay-theme();
44+
@include _mat-form-field-native-select-theme($theme);
4345

4446
.mat-mdc-form-field.mat-accent {
4547
@include _mdc-text-field-color-styles(secondary);

0 commit comments

Comments
 (0)