1+ @use ' sass:map' ;
12@use ' sass:math' ;
2- @use ' ../core/tokens/m2/mat/form-field' as tokens-mat-form-field ;
3- @use ' ../core/tokens/token-utils' ;
3+ @use ' @material/theme/theme-color' as mdc-theme-color ;
4+ @use ' ../core/theming/palette' ;
5+ @use ' ../core/mdc-helpers/mdc-helpers' ;
46
57// Width of the Material Design form-field select arrow.
68$mat-form-field-select-arrow-width : 10px ;
@@ -10,8 +12,6 @@ $mat-form-field-select-arrow-height: 5px;
1012// that the absolute positioned arrow does not overlap the select content.
1113$mat-form-field-select-horizontal-end-padding : $mat-form-field-select-arrow-width + 5px ;
1214
13- $_tokens : tokens-mat-form-field .$prefix , tokens-mat-form-field .get-token-slots ();
14-
1515// Mixin that creates styles for native select controls in a form-field.
1616@mixin private-form-field-native-select () {
1717 // Remove the native select down arrow and ensure that the native appearance
@@ -30,18 +30,6 @@ $_tokens: tokens-mat-form-field.$prefix, tokens-mat-form-field.get-token-slots()
3030 & :not (:disabled ) {
3131 cursor : pointer ;
3232 }
33-
34- & :not (.mat-mdc-native-select-inline ) {
35- @include token-utils .use-tokens ($_tokens ...) {
36- option {
37- @include token-utils .create-token-slot (color , select- option- text- color);
38- }
39-
40- option :disabled {
41- @include token-utils .create-token-slot (color , select- disabled- option- text- color);
42- }
43- }
44- }
4533 }
4634
4735 // Native select elements with the `matInput` directive should have Material Design
@@ -64,26 +52,12 @@ $_tokens: tokens-mat-form-field.$prefix, tokens-mat-form-field.get-token-slots()
6452 // Make the arrow non-clickable so the user can click on the form control under it.
6553 pointer-events : none ;
6654
67- @include token-utils .use-tokens ($_tokens ...) {
68- @include token-utils .create-token-slot (color , enabled- select- arrow- color);
69- }
70-
7155 [dir = ' rtl' ] & {
7256 right : auto ;
7357 left : 0 ;
7458 }
7559 }
7660
77- @include token-utils .use-tokens ($_tokens ...) {
78- & .mat-focused .mat-mdc-form-field-infix ::after {
79- @include token-utils .create-token-slot (color , focus- select- arrow- color);
80- }
81-
82- & .mat-form-field-disabled .mat-mdc-form-field-infix ::after {
83- @include token-utils .create-token-slot (color , disabled- select- arrow- color);
84- }
85- }
86-
8761 // Add padding on the end of the native select so that the content does not
8862 // overlap with the Material Design arrow.
8963 .mat-mdc-form-field-input-control {
@@ -95,3 +69,66 @@ $_tokens: tokens-mat-form-field.$prefix, tokens-mat-form-field.get-token-slots()
9569 }
9670 }
9771}
72+
73+ // Gets the color to use for some text that is highlighted while a select has focus.
74+ @function _get-focused-arrow-color ($palette ) {
75+ @return rgba (mdc-theme-color .prop-value ($palette ), 0.87 );
76+ }
77+
78+ @mixin private-form-field-native-select-color ($config ) {
79+ @include mdc-helpers .using-mdc-theme ($config ) {
80+ // These values are taken from the MDC select implementation:
81+ // https://github.com/material-components/material-components-web/blob/master/packages/mdc-select/_select-theme.scss
82+ $dropdown-icon-color : rgba (mdc-theme-color .prop-value (on-surface ), 0.54 );
83+ $disabled-dropdown-icon-color : rgba (mdc-theme-color .prop-value (on-surface ), 0.38 );
84+
85+ select .mat-mdc-form-field-input-control :not (.mat-mdc-native-select-inline ) {
86+ // On dark themes we set the native `select` color to some shade of white,
87+ // however the color propagates to all of the `option` elements, which are
88+ // always on a white background inside the dropdown, causing them to blend in.
89+ // Since we can't change background of the dropdown, we need to explicitly
90+ // reset the color of the options to something dark.
91+ @if (map .get ($config , is-dark )) {
92+ option {
93+ color : palette .$dark-primary-text ;
94+ }
95+
96+ option :disabled {
97+ color : palette .$dark-disabled-text ;
98+ }
99+ }
100+ }
101+
102+ .mat-mdc-form-field-type-mat-native-select {
103+ .mat-mdc-form-field-infix ::after {
104+ color : $dropdown-icon-color ;
105+ }
106+
107+ & .mat-focused {
108+ & .mat-primary {
109+ .mat-mdc-form-field-infix ::after {
110+ color : _get-focused-arrow-color (primary );
111+ }
112+ }
113+
114+ & .mat-accent {
115+ .mat-mdc-form-field-infix ::after {
116+ color : _get-focused-arrow-color (secondary );
117+ }
118+ }
119+
120+ & .mat-warn {
121+ .mat-mdc-form-field-infix ::after {
122+ color : _get-focused-arrow-color (error );
123+ }
124+ }
125+ }
126+
127+ & .mat-form-field-disabled {
128+ .mat-mdc-form-field-infix ::after {
129+ color : $disabled-dropdown-icon-color ;
130+ }
131+ }
132+ }
133+ }
134+ }
0 commit comments