-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathindex.html
1735 lines (1524 loc) · 63.5 KB
/
index.html
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
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Open UI's selectlist demos</title>
<link rel="icon" type="image/png" href="https://edgestatic.azureedge.net/welcome/static/favicon.png">
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Open UI's <code><selectlist></code> demos</h1>
<p>The purpose of the <a href="https://open-ui.org/">Open UI</a> group is to provide the web platform with UI controls that can be styled and extended by web developers. The <code><selectlist></code> element is one of the early browser implementations of <a href="https://open-ui.org/components/selectlist">the Open UI selectlist specification</a>.</p>
<p class="info"><code><selectlist></code> is available in Chromium-based browsers and requires a Canary version as well as the <em><strong>Experimental Web Platform features</strong></em> flag to be enabled in <strong>about:flags</strong>.</p>
<p>The demos below show how the <code><selectlist></code> UI control can be used to achieve what was once only possible with custom selects.<br>
The control is still in its early days and these demos have been made to find bugs with the implementation and limitations in the architecture. They are not complete and have bugs.</p>
<p class="info"><strong>Also note that some of the demos are not fully accessible.</strong> The experimental <code><selectlist></code> control allows to go very far in extending its default behavior. Some of the demos extend and even replace the entire shadow DOM of the control in order to push the prototype to its limits. As a result some demos are inaccessible. <strong>These are currently serving as a way to provoke discussions aimed at evolving the specification and implementation.</strong></p>
</header>
<div class="sample">
<h2>Rounded select</h2>
<p>Create a rounded listbox, with inline options that are constrained within the circle.</p>
<p><strong>Note: </strong>The CSS code for this demo adds a couple of pseudo-elements to draw a curve between the button and the listbox. To make this work in cases where there isn't enough room below the button to fit the listbox, some JavaScript code is used to position the pseudo-elements correctly. Also, these elements are hidden as soon as you start scrolling around.</p>
<style>
.bubble {
width: 300px;
margin: 0 auto;
display: block;
--main-color: #24aaa0;
}
.bubble .anchor {
width: 10%;
margin: 0 auto;
aspect-ratio: 1;
background: var(--main-color);
border-radius: 50%;
transform: translateY(47%);
text-align: center;
cursor: pointer;
border: none;
display: block;
}
.bubble listbox {
box-shadow: none;
margin: 0;
padding: 0;
border: none;
transform: translateY(-6px);
background: transparent;
overflow: hidden;
}
.bubble.above listbox {
transform: translateY(35px);
}
.bubble .listbox-inner {
aspect-ratio: 1;
border-radius: 50%;
background: var(--main-color);
position: relative;
margin-top: 10px;
}
.bubble.above .listbox-inner {
margin-bottom: 10px;
margin-top: unset;
/* When the listbox is above the button, some of it hides the selected-value.
We can't fix this with z-index because the listbox is in the top-layer.
So instead we clip a little hole at the bottom of the listbox to make sure
the selected-value is still visible. Making sure that the before/after pseudo
don't get hidden because that's where we display the curve that links the listbox
to the button. */
clip-path: polygon(0 0, 100% 0, 100% 100%, calc(50% + 15px) calc(100% + 15px), calc(50% + 14px) 100%, 50% calc(100% - 10px), calc(50% - 14px) 100%, calc(50% - 15px) calc(100% + 15px), 0 100%);
}
.bubble .listbox-inner::before,
.bubble .listbox-inner::after {
content: "";
width: 10%;
aspect-ratio: 1;
position: absolute;
left: 106px;
background: radial-gradient(circle, white 71%, transparent 0), linear-gradient(135deg, transparent 70%, var(--main-color) 0);
top: -28px;
bottom: unset;
}
.bubble .listbox-inner::after {
right: 106px;
background: radial-gradient(circle, white 71%, transparent 0), linear-gradient(-135deg, transparent 70%, var(--main-color) 0);
left: unset;
}
.bubble.above .listbox-inner::before,
.bubble.above .listbox-inner::after {
bottom: -28px;
top: unset;
}
.bubble.above .listbox-inner::before {
background: radial-gradient(circle, white 71%, transparent 0), linear-gradient(45deg, transparent 70%, var(--main-color) 0);
}
.bubble.above .listbox-inner::after {
background: radial-gradient(circle, white 71%, transparent 0), linear-gradient(-45deg, transparent 70%, var(--main-color) 0);
}
.bubble .smileys {
width: 300px;
aspect-ratio: 1;
overflow: hidden;
text-align: center;
}
.bubble .smileys .left,
.bubble .smileys .right {
content: "";
display: block;
float: left;
height: 100%;
width: 50%;
/* Firefox's shapes editor saved my skin here! You don't want to do this by hand. */
shape-outside: polygon( 100% 0, 77.35% 1.46%, 54% 5%, 33.33% 12.33%, 18% 21%, 9.74% 28.72%, 3px 40.33%, 0 50%, 3px 60%, 8.67% 70.67%, 19.33% 80%, 34.67% 87.67%, 52.54% 93.63%, 70.59% 97.87%, 100% 100%, 0 100%, 0 0);
}
.bubble .smileys .right {
float: right;
shape-outside: polygon( 0px 0, 23.64% 1.41%, 42.67% 4.67%, 64.67% 11.33%, 82% 20.33%, 92% 30%, 97.13% 39.15%, 100% 50%, 96.67% 62.67%, 90% 71%, 78.67% 82%, 59.42% 90.4%, 35.33% 97%, 0 100%, 100% 100%, 100% 0);
}
.bubble .smileys option {
font-size: 25px;
margin: 0;
padding: 0;
border-radius: 50%;
display: inline-block;
width: 35px;
aspect-ratio: 1;
cursor: pointer;
}
.bubble .smileys option:hover {
background: #0003;
}
/* When the document scrolls, remove the before/after pseudos
since they won't be positioned correctly. */
.bubble.scrolled .listbox-inner::before,
.bubble.scrolled .listbox-inner::after {
display: none;
}
.bubble.scrolled .listbox-inner {
clip-path: none;
}
</style>
<selectlist class="bubble">
<button type=selectlist class=anchor>
<selectedoption></selectedoption>
</button>
<listbox>
<div class="listbox-inner">
<div class="smileys">
<div class="left"></div>
<div class="right"></div>
<option value="">😀</option>
<option value="">😁</option>
<option value="">😂</option>
<option value="">🤣</option>
<option value="">😃</option>
<option value="">😄</option>
<option value="">😅</option>
<option value="">😆</option>
<option value="">😉</option>
<option value="">😊</option>
<option value="">😋</option>
<option value="">😎</option>
<option value="">😍</option>
<option value="">😘</option>
<option value="">🥰</option>
<option value="">😗</option>
<option value="">😙</option>
<option value="">🥲</option>
<option value="">😚</option>
<option value="">🙂</option>
<option value="">🤗</option>
<option value="">🤩</option>
<option value="">🤔</option>
<option value="">🤨</option>
<option value="">😐</option>
<option value="">😑</option>
<option value="">😶</option>
<option value="">🙄</option>
<option value="">😏</option>
<option value="">😣</option>
<option value="">😥</option>
<option value="">😮</option>
<option value="">🤐</option>
<option value="">😯</option>
<option value="">😪</option>
<option value="">😫</option>
<option value="">🥱</option>
<option value="">😴</option>
<option value="">😌</option>
<option value="">😛</option>
<option value="">😜</option>
</div>
</div>
</listbox>
</selectlist>
<script>
const bubbleSelect = document.querySelector('.bubble');
const bubbleButton = bubbleSelect.querySelector('button');
const bubbleListbox = bubbleSelect.querySelector('listbox');
bubbleSelect.addEventListener('popovershow', e => {
// Reset the class we use to know if the document was scrolled.
bubbleSelect.classList.remove('scrolled');
// Unfortunately we need to bump this on the event loop to make sure the
// popover is really positioned.
setTimeout(() => {
// Remove scrollTop to compare apples to apples. The popover is in the top-layer
// and fixed positioned, so it's not affected by the scroll position.
// Whereas the button is in the normal static flow of the document, so it is.
const popoverTop = bubbleListbox.offsetTop;
const buttonTop = bubbleButton.offsetTop - document.documentElement.scrollTop;
bubbleSelect.classList.toggle('above', popoverTop < buttonTop);
}, 0);
});
// On scroll, the popover won't move, because it's in the top-layer.
// So the before/after pseudos we use to draw a curve between the listbox and the button
// won't be positioned correctly anymore. So just hide them by setting a class on the
// selectlist.
addEventListener('scroll', () => {
bubbleSelect.classList.add('scrolled');
});
</script>
</div>
<div class="sample">
<h2>Vertically aligned options</h2>
<p>Vertically align the popover so the selected option's vertical position matches that of the selected-value.</p>
<p><strong>Note</strong>: this only works when the popover would normally appear below the button. The logic fails when the browser auto-places the popover above the button.</p>
<style>
.vertical-align {
font-family: Roboto, Helvetica, Arial, sans-serif;
font-size: 14px;
position: relative;
}
.vertical-align::before {
content: "";
width: 0;
height: 0;
border-top: 6px solid black;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
position: absolute;
top: calc(50% - 3px);
right: 8px;
}
.vertical-align button {
font-family: inherit;
font-size: inherit;
border-radius: 3px;
border: 0;
background: #eee;
padding: 8px;
text-align: start;
display: flex;
flex-direction: column;
gap: 2px;
cursor: pointer;
min-width: 300px;
background-image: linear-gradient(to right, #ddd, #ddd);
background-size: 0 100%;
background-repeat: no-repeat;
}
.vertical-align:focus-within button {
animation: 200ms ease-out fill-button forwards;
}
@keyframes fill-button {
to {
background-size: 100% 100%;
}
}
.vertical-align button label {
font-size: 12px;
color: #5f6368;
}
.vertical-align listbox {
padding: 0;
border-radius: 0;
border: 0;
box-shadow: 0px 8px 10px 1px rgba(0, 0, 0, 0.14), 0px 3px 14px 2px rgba(0, 0, 0, 0.12), 0px 5px 5px -3px rgba(0, 0, 0, 0.2);
}
.vertical-align option {
padding: 0 8px;
height: 36px;
line-height: 36px;
}
.vertical-align option:hover {
background-color: #eee;
}
.vertical-align listbox {
animation: 120ms cubic-bezier(0, 0.1, 0.1, 1) 200ms 1 forwards reveal-popover;
opacity: 0;
}
@keyframes reveal-popover {
to {
opacity: 1;
}
}
</style>
<selectlist class="vertical-align">
<button type=selectlist>
<label>Vegetable</label>
<selectedoption></selectedoption>
</button>
<listbox>
<option value="Courgette">Courgette</option>
<option value="Aubergine">Aubergine</option>
<option value="Carrot">Carrot</option>
<option value="Leek" selected>Leek</option>
<option value="Broccoli">Broccoli</option>
<option value="Lettuce">Lettuce</option>
<option value="Pumpkin">Pumpkin</option>
<option value="Pepper">Pepper</option>
</listbox>
</selectlist>
<script>
const verticalAlignSelect = document.querySelector('.vertical-align');
const verticalAlignButton = verticalAlignSelect.querySelector('button');
const verticalAlignpopover = verticalAlignSelect.querySelector('listbox');
let optionHeight = null;
verticalAlignpopover.addEventListener('toggle', event => {
if (event.newState != 'open') {
return;
}
// Initialize the height of an option.
if (!optionHeight) {
optionHeight = verticalAlignpopover.querySelector('option').offsetHeight;
}
// Calculate the vertical position of the selected option.
const index = [...verticalAlignpopover.children].indexOf(verticalAlignSelect.selectedOption);
const delta = optionHeight + (index * optionHeight) - 2;
// Set the popover's top position to match the selected option.
verticalAlignpopover.style.transform = `translateY(-${delta}px)`;
});
</script>
</div>
<div class="sample">
<h2>Combobox</h2>
<p>Add a input field to the popover that can be used to filter the options.</p>
<p><strong>Note</strong>: the button and popover have different styles whether the popover is visible or not, and whether it's above the button.</p>
<style>
.combobox {
width: 300px;
}
.combobox button {
width: 100%;
border-radius: 4px;
border: 1px solid #ccc;
background: #f6f4f7;
padding: 5px;
text-align: start;
}
.combobox:open button {
border-radius: 4px 4px 0 0;
border-bottom-color: #f6f4f7;
}
.combobox:open.above button {
border-radius: 0 0 4px 4px;
border-bottom-color: #ccc;
border-top-color: #f6f4f7;
}
.combobox listbox {
box-shadow: none;
padding: 5px;
margin: -1px 0 0 0;
border-radius: 0 0 4px 4px;
border: 1px solid #ccc;
border-width: 0 1px 1px;
background: #f6f4f7;
box-sizing: border-box;
}
.combobox.above listbox {
border-radius: 4px 4px 0 0;
border-width: 1px 1px 0;
}
.combobox option {
padding: 5px;
}
.combobox option:hover,
.combobox option:focus {
background: #097ff5;
color: white;
outline: 0;
}
.combobox option .highlight {
text-decoration: underline;
}
.combobox input[type="search"] {
width: 100%;
margin-bottom: 5px;
padding: 5px;
box-sizing: border-box;
border: 1px solid #ccc;
}
.combobox .options {
max-height: 50vh;
overflow-y: auto;
overflow-x: hidden;
}
</style>
<selectlist class="combobox">
<button type=selectlist>
<selectedoption hidden></selectedoption>
<span class="visible-value">Felids</span>
</button>
<listbox>
<input type="search">
<div class="options" tabindex="-1">
<option value="Asian golden cat">Asian golden cat</option>
<option value="Bay cat">Bay cat</option>
<option value="Marbled cat">Marbled cat</option>
<option value="African golden cat">African golden cat</option>
<option value="Caracal">Caracal</option>
<option value="Serval">Serval</option>
<option value="Andean mountain cat">Andean mountain cat</option>
<option value="Geoffroy's cat">Geoffroy's cat</option>
<option value="Kodkod">Kodkod</option>
<option value="Margay">Margay</option>
<option value="Ocelot">Ocelot</option>
<option value="Oncilla">Oncilla</option>
<option value="Pampas cat">Pampas cat</option>
<option value="Southern tiger cat">Southern tiger cat</option>
<option value="Bobcat">Bobcat</option>
<option value="Canada lynx">Canada lynx</option>
<option value="Eurasian lynx">Eurasian lynx</option>
<option value="Iberian lynx">Iberian lynx</option>
<option value="Cheetah">Cheetah</option>
<option value="Jaguarundi">Jaguarundi</option>
<option value="Cougar">Cougar</option>
<option value="Pallas's cat">Pallas's cat</option>
<option value="Fishing cat">Fishing cat</option>
<option value="Flat-headed cat">Flat-headed cat</option>
<option value="Leopard cat">Leopard cat</option>
<option value="Rusty-spotted cat">Rusty-spotted cat</option>
<option value="Sunda leopard cat">Sunda leopard cat</option>
<option value="African wildcat">African wildcat</option>
<option value="Black-footed cat">Black-footed cat</option>
<option value="Chinese mountain cat">Chinese mountain cat</option>
<option value="Domestic cat">Domestic cat</option>
<option value="European wildcat">European wildcat</option>
<option value="Jungle cat">Jungle cat</option>
<option value="Sand cat">Sand cat</option>
<option value="Clouded leopard">Clouded leopard</option>
<option value="Sunda clouded leopard">Sunda clouded leopard</option>
<option value="Jaguar">Jaguar</option>
<option value="Leopard">Leopard</option>
<option value="Lion">Lion</option>
<option value="Snow leopard">Snow leopard</option>
<option value="Tiger">Tiger</option>
</div>
</listbox>
</selectlist>
<script>
const combobox = document.querySelector('.combobox');
const cbButton = combobox.querySelector('button');
const cbpopover = combobox.querySelector('listbox');
const cbInput = combobox.querySelector('input[type="search"]');
const cbOptionsContainer = combobox.querySelector('.options');
const cbOptionList = [...combobox.querySelectorAll('option')].map(option => option.textContent);
const cbValue = combobox.querySelector('.visible-value');
cbpopover.addEventListener('toggle', event => {
if (event.newState == 'open') {
cbInput.focus();
}
});
cbInput.addEventListener('input', () => {
cbOptionsContainer.innerHTML = '';
let matchingOptions = 0;
cbOptionList.forEach(text => {
const index = text.toLowerCase().indexOf(cbInput.value.toLowerCase());
if (index !== -1) {
const optionElement = document.createElement('option');
optionElement.setAttribute('value', text);
const label = document.createElement('span');
label.appendChild(document.createTextNode(text.substring(0, index)));
const highlight = document.createElement('span');
highlight.classList.add('highlight');
highlight.textContent = text.slice(index, index + cbInput.value.length);
label.appendChild(highlight);
label.appendChild(document.createTextNode(text.substring(index + cbInput.value.length)));
optionElement.appendChild(label);
cbOptionsContainer.appendChild(optionElement);
matchingOptions++;
}
});
if (!matchingOptions) {
const optionElement = document.createElement('option');
optionElement.textContent = 'No matching options';
cbOptionsContainer.appendChild(optionElement);
}
});
combobox.addEventListener('change', () => {
cbValue.textContent = combobox.value;
});
// Detecting if the popover is above the button or not.
// It would be great if there was a pseudo-class for this too.
// But for now, let's do our own thing.
combobox.addEventListener('popovershow', () => {
// This requires to move our code back onto the event queue to make sure
// the popover has had the time to be displayed.
setTimeout(() => {
const popoverTop = cbpopover.offsetTop;
const buttonTop = cbButton.offsetTop - document.documentElement.scrollTop;
combobox.classList.toggle('above', popoverTop < buttonTop);
}, 0);
});
</script>
</div>
<div class="sample">
<h2>Multi-select</h2>
<p>Allow selecting multiple options from the list, displaying them in the button.</p>
<style>
.multiselect button {
background-color: rgb(255, 255, 255);
border-width: 1px;
border-style: solid;
border-color: rgb(217, 217, 217);
border-radius: 2px;
transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1) 0s;
width: 300px;
min-height: 32px;
}
.multiselect:focus-within button {
box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
border-right-width: 1px !important;
border-color: #40a9ff;
outline: 0px;
}
.multiselect .selected-values {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: flex-start;
gap: 4px;
margin: 0;
padding: 4px;
list-style: none;
}
.multiselect .selected-values li {
display: flex;
align-items: center;
box-sizing: border-box;
max-width: 100%;
height: 24px;
line-height: 22px;
cursor: default;
user-select: none;
margin-inline-end: 4px;
padding-inline-start: 8px;
padding-inline-end: 4px;
flex: 0 0 auto;
background: rgb(245, 245, 245);
border: 1px solid rgb(240, 240, 240);
border-radius: 2px;
}
.multiselect .selected-values .label {
margin-right: 4px;
white-space: pre;
text-overflow: ellipsis;
overflow: hidden;
}
.multiselect .selected-values .remove {
color: rgba(0, 0, 0, 0.45);
font-size: 10px;
cursor: pointer;
}
.multiselect option {
position: relative;
display: flex;
min-height: 22px;
color: rgba(0, 0, 0, 0.85);
font-weight: 400;
font-size: 14px;
line-height: 22px;
cursor: pointer;
padding: 5px 12px;
transition: background 0.3s ease 0s;
justify-content: space-between;
align-items: center;
}
.multiselect option[selected] {
color: rgba(0, 0, 0, 0.85);
font-weight: 600;
background-color: #e6f7ff;
}
.multiselect option[selected]::after {
content: url('data:image/svg+xml;utf8,<svg viewBox="64 64 896 896" xmlns="http://www.w3.org/2000/svg" height="12" version="1.1" width="12"><path d="M912 190h-69.9c-9.8 0-19.1 4.5-25.1 12.2L404.7 724.5 207 474a32 32 0 00-25.1-12.2H112c-6.7 0-10.4 7.7-6.3 12.9l273.9 347c12.8 16.2 37.4 16.2 50.3 0l488.4-618.9c4.1-5.1.4-12.8-6.3-12.8z"></path></svg>');
}
</style>
<selectlist class="multiselect">
<button type=selectlist>
<ul class="selected-values"></ul>
</button>
<option value="Broccolini">Broccolini</option>
<option value="Pancetta">Pancetta</option>
<option value="Potato">Potato</option>
<option value="Sausage">Sausage</option>
<option value="Gorgonzola">Gorgonzola</option>
<option value="Mushroom">Mushroom</option>
<option value="Black olives">Black olives</option>
<option value="Anchovies">Anchovies</option>
<option value="Capers">Capers</option>
<option value="Radicchio">Radicchio</option>
<option value="Eggplant">Eggplant</option>
<option value="Capsicum">Capsicum</option>
<option value="Garlic">Garlic</option>
<option value="Onions">Onions</option>
</selectlist>
<script>
const multiselect = document.querySelector('.multiselect');
const multiSelectedValuesContainer = multiselect.querySelector('.selected-values');
let multiValues = [];
multiselect.addEventListener('click', e => {
const option = e.target.closest('option');
if (!option) return;
const newValue = option.value;
if (multiValues.includes(newValue)) {
multiRemove(newValue);
} else {
multiAdd(newValue);
}
});
multiselect.addEventListener('click', e => {
const removeIcon = e.target.closest('.remove');
const selectedValue = e.target.closest('.selected-values li');
if (!removeIcon) return;
e.stopPropagation();
multiRemove(selectedValue.textContent);
}, true);
function multiAdd(value) {
multiValues.push(value);
multiRefreshSelectedValues();
multiRefreshOptions();
}
function multiRemove(toRemove) {
multiValues = multiValues.filter(value => value !== toRemove);
multiRefreshSelectedValues();
multiRefreshOptions();
}
function multiRefreshSelectedValues() {
multiSelectedValuesContainer.innerHTML = '';
multiValues.forEach(value => {
const label = document.createElement('span');
label.classList.add('label');
label.textContent = value;
const remove = document.createElement('span');
remove.classList.add('remove');
remove.innerHTML = '<svg viewBox="64 64 896 896" focusable="false" data-icon="close" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 00203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z"></path></svg>';
const li = document.createElement('li');
li.appendChild(label);
li.appendChild(remove);
multiSelectedValuesContainer.appendChild(li);
});
}
function multiRefreshOptions() {
const options = multiselect.querySelectorAll('option');
options.forEach(option => {
if (multiValues.includes(option.value)) {
option.setAttribute('selected', '');
} else {
option.removeAttribute('selected');
}
});
}
</script>
</div>
<div class="sample">
<h2>Account switcher</h2>
<p>Display more text within options, use a custom toggle button, and display an icon next to some options.</p>
<style>
.gitpod {
width: 250px;
}
.gitpod option,
.gitpod button {
font-size: 16px;
font-weight: 600;
font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, Noto Sans, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji;
cursor: pointer;
}
.gitpod button {
border: 0;
display: flex;
align-items: center;
width: max-content;
background: url(https://i.stack.imgur.com/jJa0Y.png) no-repeat center right/contain;
padding-right: 30px;
}
.gitpod::part(listbox) {
padding: 0;
border-radius: 8px;
border: 1px solid #e7e5e4;
box-shadow: none;
margin-top: 8px;
}
.gitpod option {
background-color: #fafaf9;
padding: 12px 16px;
}
.gitpod option:not(:last-child) {
border-bottom: 1px solid #e7e5e4;
}
.gitpod option:not(.action)::after {
content: attr(data-details);
display: block;
color: #a8a29e;
font-size: 14px;
font-weight: normal;
}
.gitpod option:hover {
background-color: #f5f5f4;
}
.gitpod option.action {
color: #a8a29e;
display: flex;
align-items: center;
justify-content: space-between;
}
.gitpod option.action svg {
width: 16px;
}
</style>
<selectlist class="gitpod">
<button type=selectlist>
<selectedoption></selectedoption>
</button>
<option value="Patrick Brosset" data-details="Personal Account">Patrick Brosset</option>
<option value="Microsoft Edge" data-details="Team Account">Microsoft Edge</option>
<option value="Microsoft" data-details="Organization Account">Microsoft</option>
<option value="new team" class="action">
New Team
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14" class="w-3.5"><path fill="currentColor" fill-rule="evenodd" d="M7 0a1 1 0 011 1v5h5a1 1 0 110 2H8v5a1 1 0 11-2 0V8H1a1 1 0 010-2h5V1a1 1 0 011-1z" clip-rule="evenodd"></path></svg>
</option>
</selectlist>
</div>
<div class="sample">
<h2>Scroll indicators</h2>
<p>Limit the max-height of the popover and provide scrolling.</p>
<style>
.scrollable::part(button) {
padding: .5rem;
border: 1px solid #ccc;
}
.scrollable listbox {
width: max-content;
height: max-content;
padding: 0;
border: 1px solid #ccc;
margin-top: .5rem;
}
.scrollable .scroller {
max-height: 40vh;
overflow-y: auto;
overflow-x: hidden;
}
.scrollable .indicator {
padding: .5rem;
text-align: center;
}
.scrollable .indicator:hover {
background: #eee;
}
.scrollable option {
padding: .5rem 1rem;
}
.scrollable option:hover {
background: #097ff5;
color: white;
}
</style>
<selectlist class="scrollable">
<listbox>
<div class="indicator before">▲</div>
<div class="scroller">
<option value="afghanistan">Afghanistan</option>
<option value="albania">Albania</option>
<option value="algeria">Algeria</option>
<option value="andorra">Andorra</option>
<option value="angola">Angola</option>
<option value="antigua and barbuda">Antigua and Barbuda</option>
<option value="argentina">Argentina</option>
<option value="armenia">Armenia</option>
<option value="australia">Australia</option>
<option value="austria">Austria</option>
<option value="azerbaijan">Azerbaijan</option>
<option value="bahamas">Bahamas</option>
<option value="bahrain">Bahrain</option>
<option value="bangladesh">Bangladesh</option>
<option value="barbados">Barbados</option>
<option value="belarus">Belarus</option>
<option value="belgium">Belgium</option>
<option value="belize">Belize</option>
<option value="benin">Benin</option>
<option value="bhutan">Bhutan</option>
<option value="bolivia">Bolivia</option>
<option value="bosnia and herzegovina">Bosnia and Herzegovina</option>
<option value="botswana">Botswana</option>
<option value="brazil">Brazil</option>
<option value="brunei ">Brunei </option>
<option value="bulgaria">Bulgaria</option>
<option value="burkina faso">Burkina Faso</option>
<option value="burundi">Burundi</option>
<option value="côte d'ivoire">Côte d'Ivoire</option>
<option value="cabo verde">Cabo Verde</option>
<option value="cambodia">Cambodia</option>
<option value="cameroon">Cameroon</option>
<option value="canada">Canada</option>
<option value="central african republic">Central African Republic</option>
<option value="chad">Chad</option>
<option value="chile">Chile</option>
<option value="china">China</option>
<option value="colombia">Colombia</option>
<option value="comoros">Comoros</option>
<option value="congo (congo-brazzaville)">Congo (Congo-Brazzaville)</option>
<option value="costa rica">Costa Rica</option>
<option value="croatia">Croatia</option>
<option value="cuba">Cuba</option>
<option value="cyprus">Cyprus</option>
<option value="czechia (czech republic)">Czechia (Czech Republic)</option>
<option value="democratic republic of the congo">Democratic Republic of the Congo</option>
<option value="denmark">Denmark</option>
<option value="djibouti">Djibouti</option>
<option value="dominica">Dominica</option>
<option value="dominican republic">Dominican Republic</option>
<option value="ecuador">Ecuador</option>
<option value="egypt">Egypt</option>
<option value="el salvador">El Salvador</option>
<option value="equatorial guinea">Equatorial Guinea</option>
<option value="eritrea">Eritrea</option>
<option value="estonia">Estonia</option>
<option value="eswatini (fmr. " swaziland ")">Eswatini (fmr. "Swaziland")</option>
<option value="ethiopia">Ethiopia</option>
<option value="fiji">Fiji</option>
<option value="finland">Finland</option>
<option value="france">France</option>
<option value="gabon">Gabon</option>
<option value="gambia">Gambia</option>
<option value="georgia">Georgia</option>
<option value="germany">Germany</option>
<option value="ghana">Ghana</option>
<option value="greece">Greece</option>
<option value="grenada">Grenada</option>
<option value="guatemala">Guatemala</option>
<option value="guinea">Guinea</option>
<option value="guinea-bissau">Guinea-Bissau</option>
<option value="guyana">Guyana</option>
<option value="haiti">Haiti</option>
<option value="holy see">Holy See</option>
<option value="honduras">Honduras</option>
<option value="hungary">Hungary</option>
<option value="iceland">Iceland</option>
<option value="india">India</option>
<option value="indonesia">Indonesia</option>
<option value="iran">Iran</option>
<option value="iraq">Iraq</option>
<option value="ireland">Ireland</option>
<option value="israel">Israel</option>
<option value="italy">Italy</option>
<option value="jamaica">Jamaica</option>
<option value="japan">Japan</option>
<option value="jordan">Jordan</option>
<option value="kazakhstan">Kazakhstan</option>
<option value="kenya">Kenya</option>
<option value="kiribati">Kiribati</option>
<option value="kuwait">Kuwait</option>
<option value="kyrgyzstan">Kyrgyzstan</option>
<option value="laos">Laos</option>
<option value="latvia">Latvia</option>
<option value="lebanon">Lebanon</option>
<option value="lesotho">Lesotho</option>
<option value="liberia">Liberia</option>
<option value="libya">Libya</option>
<option value="liechtenstein">Liechtenstein</option>
<option value="lithuania">Lithuania</option>
<option value="luxembourg">Luxembourg</option>
<option value="madagascar">Madagascar</option>
<option value="malawi">Malawi</option>
<option value="malaysia">Malaysia</option>
<option value="maldives">Maldives</option>
<option value="mali">Mali</option>
<option value="malta">Malta</option>
<option value="marshall islands">Marshall Islands</option>
<option value="mauritania">Mauritania</option>
<option value="mauritius">Mauritius</option>
<option value="mexico">Mexico</option>
<option value="micronesia">Micronesia</option>
<option value="moldova">Moldova</option>
<option value="monaco">Monaco</option>
<option value="mongolia">Mongolia</option>
<option value="montenegro">Montenegro</option>