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