1
+ @use ' sass:map' ;
1
2
@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' ;
4
6
5
7
// Width of the Material Design form-field select arrow.
6
8
$mat-form-field-select-arrow-width : 10px ;
@@ -10,8 +12,6 @@ $mat-form-field-select-arrow-height: 5px;
10
12
// that the absolute positioned arrow does not overlap the select content.
11
13
$mat-form-field-select-horizontal-end-padding : $mat-form-field-select-arrow-width + 5px ;
12
14
13
- $_tokens : tokens-mat-form-field .$prefix , tokens-mat-form-field .get-token-slots ();
14
-
15
15
// Mixin that creates styles for native select controls in a form-field.
16
16
@mixin private-form-field-native-select () {
17
17
// 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()
30
30
& :not (:disabled ) {
31
31
cursor : pointer ;
32
32
}
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
- }
45
33
}
46
34
47
35
// 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()
64
52
// Make the arrow non-clickable so the user can click on the form control under it.
65
53
pointer-events : none ;
66
54
67
- @include token-utils .use-tokens ($_tokens ...) {
68
- @include token-utils .create-token-slot (color , enabled- select- arrow- color);
69
- }
70
-
71
55
[dir = ' rtl' ] & {
72
56
right : auto ;
73
57
left : 0 ;
74
58
}
75
59
}
76
60
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
-
87
61
// Add padding on the end of the native select so that the content does not
88
62
// overlap with the Material Design arrow.
89
63
.mat-mdc-form-field-input-control {
@@ -95,3 +69,66 @@ $_tokens: tokens-mat-form-field.$prefix, tokens-mat-form-field.get-token-slots()
95
69
}
96
70
}
97
71
}
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