/
select.scss
164 lines (139 loc) · 4.85 KB
/
select.scss
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
@use '@material/menu-surface' as mdc-menu-surface;
@use '@material/list' as mdc-list;
@use '../../material/core/style/variables';
@use '../../material/core/style/vendor-prefixes';
@use '../../material/core/style/private';
@use '../../cdk/a11y';
$mat-select-arrow-size: 5px !default;
$mat-select-arrow-margin: 4px !default;
$mat-select-panel-max-height: 256px !default;
$mat-select-placeholder-arrow-space: 2 *
($mat-select-arrow-size + $mat-select-arrow-margin);
$leading-width: 12px !default;
$scale: 0.75 !default;
// We base the select panel styling on top of MDC's menu styles and we
// implement the trigger ourselves since MDC doesn't provide an equivalent.
@include mdc-menu-surface.core-styles($query: structure);
.mat-mdc-select {
display: inline-block;
width: 100%;
outline: none;
}
.mat-mdc-select-trigger {
display: inline-table;
cursor: pointer;
position: relative;
box-sizing: border-box;
.mat-mdc-select-disabled & {
@include vendor-prefixes.user-select(none);
cursor: default;
}
}
.mat-mdc-select-value {
display: table-cell;
max-width: 0;
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.mat-mdc-select-value-text {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.mat-mdc-select-arrow-wrapper {
display: table-cell;
vertical-align: middle;
// When used in a box appearance form-field the arrow should be shifted up 40%.
.mat-form-field-appearance-fill & {
transform: translateY(-40%);
}
}
.mat-mdc-select-arrow {
width: $mat-select-arrow-size * 2;
height: $mat-select-arrow-size;
position: relative;
svg {
fill: currentColor;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}
// Note that the `.mdc-menu-surface` is here in order to bump up the specificity
// and avoid interference with `mat-menu` which uses the same mixins from MDC.
.mdc-menu-surface.mat-mdc-select-panel {
width: 100%; // Ensures that the panel matches the overlay width.
max-height: $mat-select-panel-max-height;
position: static; // MDC uses `absolute` by default which will throw off our positioning.
outline: 0;
// Note that we include this private mixin, because the public
// one adds a bunch of styles that we aren't using for the menu.
@include mdc-list.deprecated-base_($query: structure);
@include a11y.high-contrast(active, off) {
outline: solid 1px;
}
.cdk-overlay-pane:not(.mat-mdc-select-panel-above) & {
border-top-left-radius: 0;
border-top-right-radius: 0;
transform-origin: top center;
}
.mat-mdc-select-panel-above & {
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
transform-origin: bottom center;
}
}
.mat-mdc-select-placeholder {
// Delay the transition until the label has animated about a third of the way through, in
// order to prevent the placeholder from overlapping for a split second.
transition: color variables.$swift-ease-out-duration
private.private-div(variables.$swift-ease-out-duration, 3)
variables.$swift-ease-out-timing-function;
._mat-animation-noopable & {
transition: none;
}
.mat-form-field-hide-placeholder & {
color: transparent;
// Overwrite browser specific CSS properties that can overwrite the `color` property.
// Some developers seem to use this approach to easily overwrite the placeholder / label color.
-webkit-text-fill-color: transparent;
// Remove the transition to prevent the placeholder
// from overlapping when the label comes back down.
transition: none;
// Prevents the '...' from showing on the parent element.
display: block;
}
}
// Our MDC form field implementation is based on the MDC text field which doesn't include styles
// for select. The select specific styles are not present as they don't use their text field as a
// container. Below are the styles to account for the select arrow icon at the end.
.mat-mdc-form-field-type-mat-select {
&.mat-form-field-appearance-fill {
.mdc-floating-label {
max-width: calc(100% - #{$mat-select-placeholder-arrow-space});
}
.mdc-floating-label--float-above {
$arrow-scale: private.private-div($mat-select-placeholder-arrow-space, $scale);
max-width: calc(100% / #{$scale} - #{$arrow-scale});
}
}
&.mat-form-field-appearance-outline {
.mdc-notched-outline__notch {
max-width: calc(100% - #{2 * ($mat-select-placeholder-arrow-space + $leading-width)});
}
.mdc-text-field--label-floating .mdc-notched-outline__notch {
max-width: calc(100% - #{$leading-width * 2});
}
}
}
// Used to prevent inline elements from collapsing if their text bindings
// become empty. This is preferrable to inserting a blank space, because the
// space can be read out by screen readers (see #21725).
.mat-mdc-select-min-line:empty::before {
content: ' ';
white-space: pre;
width: 1px;
}