-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Expand file tree
/
Copy pathoption.scss
More file actions
208 lines (178 loc) · 7.44 KB
/
option.scss
File metadata and controls
208 lines (178 loc) · 7.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
@use '@angular/cdk';
@use './m3-option';
@use '../../list/m3-list';
@use '../tokens/token-utils';
@use '../style/vendor-prefixes';
@use '../style/layout-common';
$fallbacks: m3-option.get-tokens();
$_side-padding: 16px;
.mat-mdc-option {
@include vendor-prefixes.user-select(none);
@include vendor-prefixes.smooth-font();
display: flex;
position: relative;
align-items: center;
justify-content: flex-start;
overflow: hidden;
min-height: 48px;
padding: 0 16px;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
color: token-utils.slot(option-label-text-color, $fallbacks);
font-family: token-utils.slot(option-label-text-font, $fallbacks);
line-height: token-utils.slot(option-label-text-line-height, $fallbacks);
font-size: token-utils.slot(option-label-text-size, $fallbacks);
letter-spacing: token-utils.slot(option-label-text-tracking, $fallbacks);
font-weight: token-utils.slot(option-label-text-weight, $fallbacks);
// Increase specificity to override styles from list theme.
&:hover:not(.mdc-list-item--disabled) {
background-color: token-utils.slot(option-hover-state-layer-color, $fallbacks);
}
&:focus.mdc-list-item,
&.mat-mdc-option-active.mdc-list-item {
background-color: token-utils.slot(option-focus-state-layer-color, $fallbacks);
outline: 0;
}
&.mdc-list-item--selected:not(.mdc-list-item--disabled) {
// Overide selected colors for non disabled list items except:
// - when active, focused, or hovered so still indicates that state to the user.
// - multiple mode since it already has the checkbox to show the selected state.
&:not(.mat-mdc-option-active,.mat-mdc-option-multiple,:focus,:hover) {
background-color: token-utils.slot(option-selected-state-layer-color, $fallbacks);
.mdc-list-item__primary-text {
color: token-utils.slot(option-selected-state-label-text-color, $fallbacks);
}
}
}
// Opt-in label color for multi-select selected options. Unlike single-select,
// no background-color change is applied here - the checkbox communicates selection.
// Token defaults to null, so this rule only takes effect when the user sets it.
&.mdc-list-item--selected:not(.mdc-list-item--disabled).mat-mdc-option-multiple {
&:not(.mat-mdc-option-active,:focus,:hover) {
.mdc-list-item__primary-text {
color: token-utils.slot(option-multiple-selected-state-label-text-color, $fallbacks);
}
}
}
.mat-pseudo-checkbox {
--mat-pseudo-checkbox-minimal-selected-checkmark-color: #{
token-utils.slot(option-selected-state-label-text-color, $fallbacks)};
}
&.mdc-list-item {
// If the MDC list is loaded after the option, this gets overwritten which breaks the text
// alignment. Ideally we'd wrap all the MDC mixins above with this selector, but the increased
// specificity breaks some internal overrides.
align-items: center;
// List items in MDC have a default background color which can be different from the container
// in which the option is projected. Set the base background to transparent since options
// should always have the same color as their container.
background: transparent;
}
&.mdc-list-item--disabled {
// This is the same as `mdc-list-mixins.list-disabled-opacity` which
// we can't use directly, because it comes with some selectors.
cursor: default;
// Prevent clicking on disabled options with mouse. Support focusing on disabled option using
// keyboard, but not with mouse.
pointer-events: none;
// Give the visual content of this list item a lower opacity. This creates the "gray" appearance
// for disabled state. Set the opacity on the pseudo checkbox and projected content. Set
// opacity only on the visual content rather than the entire list-item so we don't affect the
// focus ring from `.mat-focus-indicator`.
//
// MatOption uses a child `<div>` element for its focus state to align with how ListItem does
// its focus state.
.mat-mdc-option-pseudo-checkbox, .mdc-list-item__primary-text, > mat-icon {
opacity: 0.38;
}
}
// Note that we bump the padding here, rather than padding inside the
// group so that ripples still reach to the edges of the panel.
.mat-mdc-optgroup &:not(.mat-mdc-option-multiple) {
padding-left: $_side-padding * 2;
[dir='rtl'] & {
padding-left: $_side-padding;
padding-right: $_side-padding * 2;
}
}
.mat-icon,
.mat-pseudo-checkbox-full {
margin-right: $_side-padding;
flex-shrink: 0;
[dir='rtl'] & {
margin-right: 0;
margin-left: $_side-padding;
}
}
.mat-pseudo-checkbox-minimal {
margin-left: $_side-padding;
flex-shrink: 0;
[dir='rtl'] & {
margin-right: $_side-padding;
margin-left: 0;
}
}
// Increase specificity because ripple styles are part of the `mat-core` mixin and can
// potentially overwrite the absolute position of the container.
.mat-mdc-option-ripple {
@include layout-common.fill;
// Disable pointer events for the ripple container because the container will overlay the
// user content and we don't want to disable mouse events on the user content.
// Pointer events can be safely disabled because the ripple trigger element is the host element.
pointer-events: none;
}
// Needs to be overwritten explicitly, because the style can
// leak in from the list and cause the text to truncate.
.mdc-list-item__primary-text {
white-space: normal;
// MDC assigns the typography to this element, rather than the option itself, which will break
// existing overrides. Set all of the typography-related properties to `inherit` so that any
// styles set on the host can propagate down.
font-size: inherit;
font-weight: inherit;
letter-spacing: inherit;
line-height: inherit;
font-family: inherit;
text-decoration: inherit;
text-transform: inherit;
margin-right: auto;
[dir='rtl'] & {
margin-right: 0;
margin-left: auto;
}
}
@include cdk.high-contrast {
// In single selection mode, the selected option is indicated by changing its
// background color, but that doesn't work in high contrast mode. We add an
// alternate indication by rendering out a circle.
&.mdc-list-item--selected:not(:has(.mat-mdc-option-pseudo-checkbox))::after {
$size: 10px;
content: '';
position: absolute;
top: 50%;
right: $_side-padding;
transform: translateY(-50%);
width: $size;
height: 0;
border-bottom: solid $size;
border-radius: $size;
}
[dir='rtl'] &.mdc-list-item--selected:not(:has(.mat-mdc-option-pseudo-checkbox))::after {
right: auto;
left: $_side-padding;
}
}
}
$list-fallbacks: m3-list.get-tokens();
.mat-mdc-option-multiple {
// Multi-select options in the selected state aren't supposed to change their background color,
// because the checkbox already indicates that they're selected. This happened to work in M2,
// due to `list-item-selected-container-color` being the same as `list-item-container-color`,
// but that's no longer the case in M3. This overrides ensures that the appearance is consistent.
--mat-list-list-item-selected-container-color: #{
token-utils.slot(list-list-item-container-color, $list-fallbacks, $fallback: transparent)};
}
// For options, render the focus indicator when the class .mat-mdc-option-active is present.
.mat-mdc-option-active .mat-focus-indicator::before {
content: '';
}