Skip to content

Commit 10cc9cf

Browse files
authored
fix(material-experimental/mdc-select): correct some differences between (#22108)
* fix(material-experimental/mdc-select): correct some differences between mat-select and native select * fixup! fix(material-experimental/mdc-select): correct some differences between
1 parent fa7ed4c commit 10cc9cf

File tree

2 files changed

+57
-13
lines changed

2 files changed

+57
-13
lines changed

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

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
@use 'sass:map';
2+
@use '../mdc-helpers/mdc-helpers';
23
@use '../../material/core/theming/theming';
34
@use '../../cdk/a11y';
45
@use '../../material/core/theming/palette';
6+
@use '@material/theme/theme-color' as mdc-theme-color;
57

68
// Width of the Material Design form-field select arrow.
79
$mat-form-field-select-arrow-width: 10px;
@@ -68,7 +70,6 @@ $mat-form-field-select-horizontal-end-padding: $mat-form-field-select-arrow-widt
6870
border-right: ($mat-form-field-select-arrow-width / 2) solid transparent;
6971
border-top: $mat-form-field-select-arrow-height solid;
7072
position: absolute;
71-
top: 50%;
7273
right: 0;
7374

7475
// Make the arrow non-clickable so the user can click on the form control under it.
@@ -92,20 +93,64 @@ $mat-form-field-select-horizontal-end-padding: $mat-form-field-select-arrow-widt
9293
}
9394
}
9495

96+
// Gets the color to use for some text that is highlighted while a select has focus.
97+
@function _get-focused-arrow-color($palette) {
98+
@return rgba(mdc-theme-color.prop-value($palette), 0.87);
99+
}
100+
95101
@mixin private-form-field-native-select-color($config) {
96-
select.mat-mdc-input-element {
97-
// On dark themes we set the native `select` color to some shade of white,
98-
// however the color propagates to all of the `option` elements, which are
99-
// always on a white background inside the dropdown, causing them to blend in.
100-
// Since we can't change background of the dropdown, we need to explicitly
101-
// reset the color of the options to something dark.
102-
@if (map.get($config, is-dark)) {
103-
option {
104-
color: palette.$dark-primary-text;
102+
@include mdc-helpers.mat-using-mdc-theme($config) {
103+
// These values are taken from the MDC select implementation:
104+
// https://github.com/material-components/material-components-web/blob/master/packages/mdc-select/_select-theme.scss
105+
$dropdown-icon-color: rgba(mdc-theme-color.prop-value(on-surface), 0.54);
106+
$disabled-dropdown-icon-color: rgba(mdc-theme-color.prop-value(on-surface), 0.38);
107+
108+
select.mat-mdc-input-element {
109+
// On dark themes we set the native `select` color to some shade of white,
110+
// however the color propagates to all of the `option` elements, which are
111+
// always on a white background inside the dropdown, causing them to blend in.
112+
// Since we can't change background of the dropdown, we need to explicitly
113+
// reset the color of the options to something dark.
114+
@if (map.get($config, is-dark)) {
115+
option {
116+
color: palette.$dark-primary-text;
117+
}
118+
119+
option:disabled {
120+
color: palette.$dark-disabled-text;
121+
}
122+
}
123+
}
124+
125+
.mat-mdc-form-field-type-mat-native-select {
126+
.mat-mdc-form-field-infix::after {
127+
color: $dropdown-icon-color;
105128
}
106129

107-
option:disabled {
108-
color: palette.$dark-disabled-text;
130+
&.mat-focused {
131+
&.mat-primary {
132+
.mat-mdc-form-field-infix::after {
133+
color: _get-focused-arrow-color(primary);
134+
}
135+
}
136+
137+
&.mat-accent {
138+
.mat-mdc-form-field-infix::after {
139+
color: _get-focused-arrow-color(secondary);
140+
}
141+
}
142+
143+
&.mat-warn {
144+
.mat-mdc-form-field-infix::after {
145+
color: _get-focused-arrow-color(error);
146+
}
147+
}
148+
}
149+
150+
&.mat-form-field-disabled {
151+
.mat-mdc-form-field-infix::after {
152+
color: $disabled-dropdown-icon-color;
153+
}
109154
}
110155
}
111156
}

src/material-experimental/mdc-select/select.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ $scale: 0.75 !default;
6161
}
6262

6363
.mat-mdc-select-arrow {
64-
margin: 0 $mat-select-arrow-margin;
6564
width: $mat-select-arrow-size * 2;
6665
height: $mat-select-arrow-size;
6766
position: relative;

0 commit comments

Comments
 (0)