blob: cd4ecfc9036f7c77412f9124f4c3f426084adde5 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001/**
2 * Copyright 2016 Leif Olsen. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * Copied/Modified/Inspired from/by:
19 * https://github.com/google/material-design-lite/tree/master/src/textfield
20 * http://red-team-design.com/making-html-dropdowns-not-suck/
21 * http://codepen.io/etcpe9/pen/PqyOye,
22 * http://codepen.io/pudgereyem/pen/PqBxQx
23 * https://github.com/MEYVN-digital/mdl-selectfield
24 * https://github.com/mebibou/mdl-selectfield
25 */
26
27// Use of this module requires the user to include variables from material-design-lite
28//@import "../../node_modules/material-design-lite/src/variables";
29//@import "../../node_modules/material-design-lite/src/mixins";
30
31@import "../mixins";
32
33// The container for the selectfield.
34.mdlext-selectfield {
35 box-sizing: border-box;
36 position: relative;
37 font-size: $input-text-font-size;
38 display: inline-block;
39 width: 300px;
40 max-width: 100%;
41 margin: 0;
42 padding: $input-text-vertical-spacing 0;
43
44 // Align buttons, if used.
45 & .mdl-button {
46 bottom: $input-text-vertical-spacing;
47 position: absolute;
48 }
49
50 // Styling the down arrow
51 &::after {
52 @include mdlext-arrow(bottom, $mdlext-selectfield-arrow-width, $mdlext-selectfield-arrow-length);
53
54 position: absolute;
55 right: 0.5em;
56 top: 50%;
57 transform: translateY(-50%);
58 pointer-events: none;
59 }
60}
61
62.mdlext-selectfield.is-disabled {
63 &::after {
64 color: $input-text-disabled-color;
65 @include mdlext-arrow(bottom, $mdlext-selectfield-arrow-width, $mdlext-selectfield-arrow-length, $input-text-disabled-color);
66 }
67}
68
69// Optional class to align right.
70.mdlext-selectfield--align-right {
71 text-align: right;
72}
73
74// Optional class to display at full width.
75.mdlext-selectfield--full-width {
76 width: 100%;
77}
78
79// Optional class to make the select field expandable.
80.mdlext-selectfield--expandable {
81 min-height: $input-text-button-size;
82 min-width: $input-text-button-size;
83 width: auto;
84}
85
86// Styling for the select element.
87.mdlext-selectfield__select {
88
89 // Reset select
90 box-sizing: border-box;
91 border: 0;
92 border-radius: 0;
93 -webkit-appearance: none;
94 -moz-appearance: none;
95 -ms-appearance: none;
96 appearance: none;
97 text-indent: 0.01px; // Removes default arrow from firefox
98 text-overflow: ''; // Removes default arrow from firefox
99 outline: none;
100 box-shadow: none;
101 // End Reset select
102
103 font-size: $input-text-font-size;
104 font-family: $performance_font;
105 padding: $input-text-padding calc(1.2em + #{$input-text-padding}) $input-text-padding 0;
106 width: $input-text-width;
107 border-bottom: 1px solid $input-text-bottom-border-color;
108 display: block;
109 margin: 0;
110 background: none;
111 text-align: left;
112 color: inherit;
113
114 // Mozilla, remove focusring
115 &:-moz-focusring {
116 color: transparent;
117 text-shadow: 0 0 0 #000000;
118 }
119
120 // MS, remove selected option background color
121 &:focus::-ms-value {
122 background-color: inherit;
123 color: inherit;
124 }
125
126 &::-ms-expand {
127 display: none;
128 }
129
130 .mdlext-selectfield.is-focused & {
131 outline: none;
132 }
133
134 .mdlext-selectfield.is-invalid & {
135 border-color: $input-text-error-color;
136 box-shadow: none;
137 }
138
139 fieldset[disabled] .mdlext-selectfield &,
140 .mdlext-selectfield.is-disabled & {
141 border-bottom: 1px dotted $input-text-disabled-color;
142 color: $input-text-disabled-text-color;
143 background-color: transparent;
144 }
145
146 option {
147 color: $text-color-primary;
148 box-sizing: border-box;
149 background-color: inherit;
150 }
151}
152
153// Styling for the label / floating label.
154.mdlext-selectfield__label {
155 box-sizing: border-box;
156 color: $input-text-label-color;
157 font-size: $input-text-font-size;
158 top: ($input-text-padding + $input-text-vertical-spacing);
159 bottom: 0;
160 left: 0;
161 right: 0;
162 pointer-events: none;
163 position: absolute;
164 display: block;
165 width: 100%;
166 overflow: hidden;
167 white-space: nowrap;
168 text-align: left;
169
170 .mdlext-selectfield.is-dirty &,
171 .mdlext-selectfield.has-placeholder & {
172 visibility: hidden;
173 }
174
175 // Floating Label
176 .mdlext-selectfield--floating-label & {
177 @include material-animation-default();
178 }
179
180 .mdlext-selectfield--floating-label.has-placeholder & {
181 transition: none;
182 }
183
184 fieldset[disabled] .mdlext-selectfield &,
185 .mdlext-selectfield.is-disabled.is-disabled & {
186 color: $input-text-disabled-text-color;
187 }
188
189 .mdlext-selectfield--floating-label.is-focused &,
190 .mdlext-selectfield--floating-label.is-dirty.is-dirty &,
191 .mdlext-selectfield--floating-label.has-placeholder & {
192 color: $input-text-highlight-color;
193 font-size: $input-text-floating-label-fontsize;
194 top: $input-text-vertical-spacing - ($input-text-floating-label-fontsize + $input-text-padding);
195 visibility: visible;
196 }
197
198 .mdlext-selectfield--floating-label.is-focused .mdlext-selectfield__expandable-holder &,
199 .mdlext-selectfield--floating-label.is-dirty .mdlext-selectfield__expandable-holder &,
200 .mdlext-selectfield--floating-label.has-placeholder .mdlext-selectfield__expandable-holder & {
201 top: -($input-text-floating-label-fontsize + $input-text-padding);
202 }
203
204 .mdlext-selectfield--floating-label.is-invalid & {
205 color: $input-text-error-color;
206 font-size: $input-text-floating-label-fontsize;
207 }
208
209 // The after label is the colored underline for the Selectfield.
210 &::after {
211 background-color: $input-text-highlight-color;
212 bottom: $input-text-vertical-spacing;
213 content: '';
214 height: 2px;
215 left: 45%;
216 position: absolute;
217 @include material-animation-default();
218
219 visibility: hidden;
220 width: 10px;
221 }
222
223 .mdlext-selectfield.is-focused &::after {
224 left: 0;
225 visibility: visible;
226 width: 100%;
227 }
228
229 .mdlext-selectfield.is-invalid &::after {
230 background-color: $input-text-error-color;
231 }
232}
233
234// SelectField Error.
235.mdlext-selectfield__error {
236 color: $input-text-error-color;
237 font-size: $input-text-floating-label-fontsize;
238 position: absolute;
239 margin-top: 3px;
240 visibility: hidden;
241 display: block;
242
243 .mdlext-selectfield.is-invalid & {
244 visibility: visible;
245 }
246}
247
248// Expandable Holder.
249.mdlext-selectfield__expandable-holder {
250 display: inline-block;
251 position: relative;
252 margin-left: $input-text-button-size;
253
254 @include material-animation-default();
255
256 // Safari (possibly others) need to be convinced that this field is actually
257 // visible, otherwise it cannot be tabbed to nor focused via a <label>.
258 // TODO: In some cases (Retina displays), this is big enough to render the
259 // inner element :(
260 max-width: 0.1px;
261
262 .mdlext-selectfield.is-focused &,
263 .mdlext-selectfield.is-dirty & {
264 // This is an unfortunate hack. Animating between widths in percent (%)
265 // in many browsers (Chrome, Firefox) only animates the inner visual style
266 // of the input - the outer bounding box still 'jumps'.
267 // Thus assume a sensible maximum, and animate to/from that value.
268 max-width: 600px;
269 }
270 .mdlext-selectfield__label::after {
271 bottom: 0;
272 }
273}