1- @use ' sass:map' ;
21@use ' sass:math' ;
3- @use ' @material/theme/theme-color' as mdc-theme-color ;
4- @use ' ../core/theming/palette' ;
5- @use ' ../core/mdc-helpers/mdc-helpers' ;
2+ @use ' ../core/tokens/m2/mat/form-field' as tokens-mat-form-field ;
3+ @use ' ../core/tokens/token-utils' ;
64
75// Width of the Material Design form-field select arrow.
86$mat-form-field-select-arrow-width : 10px ;
@@ -12,6 +10,8 @@ $mat-form-field-select-arrow-height: 5px;
1210// that the absolute positioned arrow does not overlap the select content.
1311$mat-form-field-select-horizontal-end-padding : $mat-form-field-select-arrow-width + 5px ;
1412
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,6 +30,18 @@ $mat-form-field-select-horizontal-end-padding: $mat-form-field-select-arrow-widt
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+ }
3345 }
3446
3547 // Native select elements with the `matInput` directive should have Material Design
@@ -52,12 +64,26 @@ $mat-form-field-select-horizontal-end-padding: $mat-form-field-select-arrow-widt
5264 // Make the arrow non-clickable so the user can click on the form control under it.
5365 pointer-events : none ;
5466
67+ @include token-utils .use-tokens ($_tokens ...) {
68+ @include token-utils .create-token-slot (color , enabled- select- arrow- color);
69+ }
70+
5571 [dir = ' rtl' ] & {
5672 right : auto ;
5773 left : 0 ;
5874 }
5975 }
6076
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+
6187 // Add padding on the end of the native select so that the content does not
6288 // overlap with the Material Design arrow.
6389 .mat-mdc-form-field-input-control {
@@ -69,66 +95,3 @@ $mat-form-field-select-horizontal-end-padding: $mat-form-field-select-arrow-widt
6995 }
7096 }
7197}
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