forked from carbon-design-system/carbon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_dropdown.scss
502 lines (412 loc) · 12.6 KB
/
_dropdown.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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
//
// Copyright IBM Corp. 2016, 2023
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//
@use '../list-box';
@use '../../config' as *;
@use '../../layer' as *;
@use '../../motion' as *;
@use '../../spacing' as *;
@use '../../theme' as *;
@use '../../type' as *;
@use '../../utilities/box-shadow' as *;
@use '../../utilities/convert';
@use '../../utilities/focus-outline' as *;
@use '../../utilities/high-contrast-mode' as *;
@use '../../utilities/skeleton' as *;
@use '../../utilities/z-index' as *;
/// Dropdown styles
/// @access public
/// @group dropdown
@mixin dropdown {
.#{$prefix}--dropdown__wrapper--inline {
display: inline-grid;
align-items: center;
grid-gap: 0 convert.to-rem(24px);
grid-template: auto / auto min-content;
&:has(.#{$prefix}--label.#{$prefix}--visually-hidden) {
grid-template: auto / auto;
}
.#{$prefix}--label {
@include type-style('body-compact-01');
}
.#{$prefix}--label,
.#{$prefix}--form__helper-text,
.#{$prefix}--form-requirement {
margin: 0;
}
.#{$prefix}--form-requirement {
grid-column: 2;
}
}
.#{$prefix}--dropdown {
@include reset;
@include focus-outline('reset');
position: relative;
display: block;
border: none;
background-color: $field;
block-size: convert.to-rem(40px);
border-block-end: 1px solid $border-strong;
color: $text-primary;
cursor: pointer;
inline-size: 100%;
list-style: none;
outline: 2px solid transparent;
transition: background-color $duration-fast-01 motion(standard, productive);
&:hover {
background-color: $field-hover;
}
}
// Menu's triggering element updated to button with Downshift v5 upgrade
.#{$prefix}--dropdown .#{$prefix}--list-box__field {
text-align: start;
}
.#{$prefix}--dropdown--lg {
block-size: convert.to-rem(48px);
max-block-size: convert.to-rem(48px);
}
.#{$prefix}--dropdown--lg .#{$prefix}--dropdown__arrow {
inset-block-start: convert.to-rem(16px);
}
.#{$prefix}--dropdown--sm {
block-size: convert.to-rem(32px);
max-block-size: convert.to-rem(32px);
}
.#{$prefix}--dropdown--sm .#{$prefix}--dropdown__arrow {
inset-block-start: convert.to-rem(8px);
}
.#{$prefix}--dropdown--open {
border-block-end-color: $border-subtle;
}
.#{$prefix}--dropdown--open .#{$prefix}--list-box__field {
outline: none;
}
.#{$prefix}--dropdown--invalid {
@include focus-outline('invalid');
.#{$prefix}--dropdown-text {
padding-inline-end: convert.to-rem(56px);
}
+ .#{$prefix}--form-requirement {
display: inline-block;
color: $text-error;
max-block-size: convert.to-rem(200px);
}
}
.#{$prefix}--dropdown__invalid-icon {
position: absolute;
fill: $support-error;
inset-block-start: 50%;
inset-inline-end: $spacing-08;
transform: translateY(-50%);
}
.#{$prefix}--dropdown--open:hover {
background-color: $field;
}
.#{$prefix}--dropdown--open:focus {
outline: 1px solid transparent;
}
.#{$prefix}--dropdown--open .#{$prefix}--dropdown-list {
@include box-shadow;
// 40px item height * 5.5 items shown
max-block-size: convert.to-rem(220px);
transition: max-height $duration-fast-02 motion(entrance, productive);
}
.#{$prefix}--dropdown--light {
background-color: $field-02;
&:hover {
background-color: $field-hover;
}
}
.#{$prefix}--dropdown--up .#{$prefix}--dropdown-list {
inset-block-end: 2rem;
}
.#{$prefix}--dropdown__arrow {
position: absolute;
fill: $icon-primary;
inset-block-start: convert.to-rem(13px);
inset-inline-end: 1rem;
pointer-events: none;
transform-origin: 50% 45%;
transition: transform $duration-fast-02 motion(standard, productive);
}
button.#{$prefix}--dropdown-text {
border: none;
// button-reset mixin contradicts with cds--dropdown-text styles
background: none;
color: $text-primary;
inline-size: 100%;
text-align: start;
&:focus {
@include focus-outline('outline');
}
}
.#{$prefix}--dropdown-text {
@include type-style('body-compact-01');
display: block;
overflow: hidden;
// Account for the border in `.cds--dropdown`
block-size: calc(100% + 1px);
// 2rem + SVG width
padding-inline: $spacing-05 convert.to-rem(42px);
text-overflow: ellipsis;
white-space: nowrap;
}
.#{$prefix}--dropdown-list {
@include reset;
@include focus-outline('reset');
@include box-shadow;
@include type-style('body-compact-01');
position: absolute;
z-index: z('dropdown');
display: flex;
// NOTE: IE, Edge, and Safari do not support two value `overflow` shorthand.
overflow: hidden auto;
flex-direction: column;
background-color: $layer;
inline-size: 100%;
list-style: none;
max-block-size: 0;
transition: max-height $duration-fast-02 motion(standard, productive);
}
// V11: Possibly deprecate
.#{$prefix}--dropdown--light .#{$prefix}--dropdown-list {
background-color: $layer;
}
.#{$prefix}--dropdown:not(.#{$prefix}--dropdown--open)
.#{$prefix}--dropdown-item {
visibility: hidden;
}
.#{$prefix}--dropdown-item {
position: relative;
opacity: 0;
transition:
visibility $duration-fast-01 motion(standard, productive),
opacity $duration-fast-01 motion(standard, productive),
background-color $duration-fast-01 motion(standard, productive);
visibility: inherit;
&:hover {
background-color: $layer-hover;
+ .#{$prefix}--dropdown-item .#{$prefix}--dropdown-link {
border-color: transparent;
}
}
&:active {
background-color: $layer-selected;
}
&:first-of-type .#{$prefix}--dropdown-link {
border-block-start-color: transparent;
}
}
.#{$prefix}--dropdown-item:last-of-type .#{$prefix}--dropdown-link {
border-block-end: none;
}
.#{$prefix}--dropdown-link {
@include focus-outline('reset');
display: block;
overflow: hidden;
padding: convert.to-rem(11px) 0;
border: 1px solid transparent;
margin: 0 $spacing-05;
block-size: convert.to-rem(40px);
border-block-start-color: $border-subtle;
color: $text-secondary;
font-weight: normal;
line-height: 1rem;
text-decoration: none;
text-overflow: ellipsis;
white-space: nowrap;
&:hover {
border-color: transparent;
color: $text-primary;
}
}
// V11: Possibly deprecate
.#{$prefix}--dropdown--light .#{$prefix}--dropdown-link {
border-block-start-color: $border-subtle-02;
}
.#{$prefix}--dropdown--sm .#{$prefix}--dropdown-link {
block-size: convert.to-rem(32px);
padding-block: convert.to-rem(7px) convert.to-rem(7px);
}
.#{$prefix}--dropdown--focused,
.#{$prefix}--dropdown-link:focus {
@include focus-outline('outline');
padding: convert.to-rem(11px) convert.to-rem(16px);
margin: 0;
}
// We don't want to apply focus styles via focus selector when using the aria-activedescendant structure
.#{$prefix}--dropdown-list[aria-activedescendant]
.#{$prefix}--dropdown-link:focus {
// Copied from .cds--dropdown-link styles
padding: convert.to-rem(11px) 0;
margin: 0 $spacing-05;
outline: none;
}
// Need added weight for item that is :focused and .cds--dropdown--focused
.#{$prefix}--dropdown-list[aria-activedescendant]
.#{$prefix}--dropdown--focused:focus {
// copied from default focus styles
@include focus-outline('outline');
padding: convert.to-rem(11px) convert.to-rem(16px);
margin: 0;
}
// Don't want to allow multiple elements have a "selected" style. Not sure why active
// had unique styles initially but creating an overwrite for the latest HTML markup for
// backwards compatibility. For the next major release it would be possible to clean up
// the HTML structure to prevent the user of :active and :focus styles which is creating
// these duplicated styles in the list. The Carbon 10 version of dropdown is already
// supporting 2 very different HTML structures.
.#{$prefix}--dropdown-list[aria-activedescendant]
.#{$prefix}--dropdown-item:active {
background-color: inherit;
}
.#{$prefix}--dropdown-item:hover .#{$prefix}--dropdown-link {
border-block-end-color: $layer-hover;
}
.#{$prefix}--dropdown--open .#{$prefix}--dropdown__arrow {
transform: rotate(-180deg);
}
.#{$prefix}--dropdown--open.#{$prefix}--dropdown--sm
.#{$prefix}--dropdown-list {
// 32px item height * 5.5 items shown
max-block-size: convert.to-rem(176px);
}
.#{$prefix}--dropdown--open .#{$prefix}--dropdown-item {
opacity: 1;
}
.#{$prefix}--dropdown--disabled {
border-block-end-color: transparent;
&:hover {
background-color: $field;
}
&:focus {
outline: none;
}
// TODO: remove in v11
.#{$prefix}--dropdown-text,
.#{$prefix}--list-box__label {
color: $text-disabled;
}
// TODO: remove in v11
.#{$prefix}--dropdown__arrow,
.#{$prefix}--list-box__menu-icon svg {
fill: $icon-disabled;
}
// V11: Possibly deprecate
&.#{$prefix}--dropdown--light:hover {
background-color: $field-02;
}
}
.#{$prefix}--dropdown--disabled .#{$prefix}--list-box__field,
.#{$prefix}--dropdown--disabled .#{$prefix}--list-box__menu-icon {
cursor: not-allowed;
}
.#{$prefix}--dropdown--auto-width {
inline-size: auto;
max-inline-size: convert.to-rem(400px);
}
.#{$prefix}--dropdown--inline {
display: inline-block;
background-color: transparent;
border-block-end-color: transparent;
inline-size: auto;
justify-self: start;
transition: background $duration-fast-01 motion(entrance, productive);
&:hover {
background-color: $layer-hover;
}
&.#{$prefix}--dropdown--disabled {
background-color: transparent;
}
.#{$prefix}--dropdown__arrow {
inset-block-start: convert.to-rem(8px);
inset-inline-end: convert.to-rem(8px);
}
}
.#{$prefix}--dropdown--inline.#{$prefix}--dropdown--open {
background-color: transparent;
}
.#{$prefix}--dropdown--inline .#{$prefix}--dropdown-text {
display: inline-block;
overflow: visible;
padding: convert.to-rem(7px) $spacing-07 convert.to-rem(7px) $spacing-04;
block-size: convert.to-rem(32px);
color: $text-primary;
}
.#{$prefix}--dropdown--inline.#{$prefix}--dropdown--disabled
.#{$prefix}--dropdown-text {
color: $text-disabled;
}
.#{$prefix}--dropdown--inline.#{$prefix}--dropdown--disabled:focus
.#{$prefix}--dropdown-text {
outline: 0;
}
.#{$prefix}--dropdown--inline.#{$prefix}--dropdown--invalid
.#{$prefix}--dropdown__invalid-icon {
inset-inline-end: convert.to-rem(32px);
}
.#{$prefix}--dropdown--inline.#{$prefix}--dropdown--invalid
.#{$prefix}--dropdown-text {
padding-inline-end: convert.to-rem(56px);
}
.#{$prefix}--dropdown--inline.#{$prefix}--dropdown--open:focus
.#{$prefix}--dropdown-list {
@include box-shadow;
}
.#{$prefix}--dropdown--inline .#{$prefix}--dropdown-link {
font-weight: normal;
}
.#{$prefix}--dropdown--show-selected .#{$prefix}--dropdown--selected {
display: block;
background-color: $layer-selected;
color: $text-primary;
&:hover {
background-color: $layer-selected-hover;
}
.#{$prefix}--dropdown-link {
border-block-start-color: transparent;
}
+ .#{$prefix}--dropdown-item .#{$prefix}--dropdown-link {
border-block-start-color: transparent;
}
.#{$prefix}--list-box__menu-item__selected-icon {
display: block;
}
}
// Skeleton State
.#{$prefix}--dropdown-v2.#{$prefix}--skeleton,
.#{$prefix}--dropdown.#{$prefix}--skeleton {
@include skeleton;
}
// Windows HCM fix
.#{$prefix}--dropdown .#{$prefix}--list-box__field {
@include high-contrast-mode('outline');
}
.#{$prefix}--list-box__menu-item__option {
@include high-contrast-mode {
outline: none;
}
}
.#{$prefix}--list-box__menu-item__selected-icon {
@include high-contrast-mode('icon-fill');
}
// readonly
.#{$prefix}--dropdown--readonly,
.#{$prefix}--dropdown--readonly:hover {
background-color: transparent;
border-block-end-color: $border-subtle;
}
.#{$prefix}--dropdown--inline.#{$prefix}--dropdown--readonly {
border-block-end-color: transparent;
}
.#{$prefix}--dropdown--readonly .#{$prefix}--list-box__field,
.#{$prefix}--dropdown--readonly .#{$prefix}--list-box__menu-icon {
cursor: default;
}
.#{$prefix}--dropdown--readonly .#{$prefix}--list-box__menu-icon svg {
fill: $icon-disabled;
}
}