-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathdropdown.e2e.ts
1028 lines (926 loc) · 49.3 KB
/
dropdown.e2e.ts
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
import { E2EPage, newE2EPage } from "@stencil/core/testing";
import { accessible, defaults, disabled, popperOwner, renders } from "../../tests/commonTests";
import dedent from "dedent";
import { html } from "../../../support/formatting";
describe("calcite-dropdown", () => {
it("renders", () =>
renders(
html`<calcite-dropdown>
<calcite-button slot="dropdown-trigger">Open dropdown</calcite-button>
<calcite-dropdown-group id="group-1">
<calcite-dropdown-item id="item-1"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-2" active> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-3"> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>`,
{ display: "inline-flex" }
));
it("defaults", async () =>
defaults("calcite-dropdown", [
{
propertyName: "overlayPositioning",
defaultValue: "absolute"
},
{
propertyName: "flipPlacements",
defaultValue: undefined
}
]));
it("can be disabled", () =>
disabled(
html`<calcite-dropdown>
<calcite-button slot="dropdown-trigger">Open dropdown</calcite-button>
<calcite-dropdown-group id="group-1">
<calcite-dropdown-item id="item-1"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-2" active> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-3"> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>`,
{ focusTarget: "child" }
));
/**
* Test helper for selected calcite-dropdown items. Expects items to have IDs to test against.
*
* @param page
* @param expectedItemIds
*/
async function assertSelectedItems(page: E2EPage, expectedItemIds: string[]): Promise<void> {
const selectedItemIds = await page.evaluate(() => {
const dropdown = document.querySelector<HTMLCalciteDropdownElement>("calcite-dropdown");
return dropdown.selectedItems.map((item) => item.id);
});
expect(selectedItemIds).toHaveLength(expectedItemIds.length);
expectedItemIds.forEach((itemId, index) => expect(selectedItemIds[index]).toEqual(itemId));
}
const dropdownSelectionModeContent = html`
<calcite-dropdown>
<calcite-button slot="dropdown-trigger" id="trigger">Open dropdown</calcite-button>
<calcite-dropdown-group id="group-1" selection-mode="multi">
<calcite-dropdown-item id="item-1"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-2" active> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-3" active> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
<calcite-dropdown-group id="group-2" selection-mode="single">
<calcite-dropdown-item id="item-4"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-5" active> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
<calcite-dropdown-group id="group-3" selection-mode="none">
<calcite-dropdown-item id="item-6"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-7" href="google.com"> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>
`;
it("renders default props when none are provided", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-dropdown>
<calcite-button slot="dropdown-trigger">Open dropdown</calcite-button>
<calcite-dropdown-group id="group-1">
<calcite-dropdown-item id="item-1"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-2" active> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-3"> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>`);
const element = await page.find("calcite-dropdown");
const group1 = await element.find("calcite-dropdown-group[id='group-1']");
expect(element).toEqualAttribute("scale", "m");
expect(element).toEqualAttribute("width", "m");
expect(element).toEqualAttribute("placement", "bottom-leading");
expect(group1).toEqualAttribute("selection-mode", "single");
});
it("renders requested props when valid props are provided", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-dropdown placement="bottom-trailing" scale="l" width="l">
<calcite-button slot="dropdown-trigger">Open dropdown</calcite-button>
<calcite-dropdown-group id="group-1" selection-mode="multi">
<calcite-dropdown-item id="item-1"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-2" active> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-3"> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>`);
const element = await page.find("calcite-dropdown");
const group1 = await element.find("calcite-dropdown-group[id='group-1']");
expect(element).toEqualAttribute("scale", "l");
expect(element).toEqualAttribute("width", "l");
expect(element).toEqualAttribute("placement", "bottom-trailing");
expect(group1).toEqualAttribute("selection-mode", "multi");
});
it("renders icons if requested and does not render icons if not requested", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-dropdown>
<calcite-button slot="dropdown-trigger">Open dropdown</calcite-button>
<calcite-dropdown-group>
<calcite-dropdown-item icon-start="grid" id="item-1"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item icon-end="grid" id="item-2" active> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item icon-start="grid" icon-end="grid" id="item-3">
Dropdown Item Content
</calcite-dropdown-item>
<calcite-dropdown-item id="item-4"> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>`);
const item1IconStart = await page.find("calcite-dropdown-item[id='item-1'] >>> .dropdown-item-icon-start");
const item1IconEnd = await page.find("calcite-dropdown-item[id='item-1'] >>> .dropdown-item-icon-end");
const item2IconStart = await page.find("calcite-dropdown-item[id='item-2'] >>> .dropdown-item-icon-start");
const item2IconEnd = await page.find("calcite-dropdown-item[id='item-2'] >>> .dropdown-item-icon-end");
const item3IconStart = await page.find("calcite-dropdown-item[id='item-3'] >>> .dropdown-item-icon-start");
const item3IconEnd = await page.find("calcite-dropdown-item[id='item-3'] >>> .dropdown-item-icon-end");
const item4IconStart = await page.find("calcite-dropdown-item[id='item-4'] >>> .dropdown-item-icon-start");
const item4IconEnd = await page.find("calcite-dropdown-item[id='item-4'] >>> .dropdown-item-icon-end");
expect(item1IconStart).not.toBeNull();
expect(item1IconEnd).toBeNull();
expect(item2IconStart).toBeNull();
expect(item2IconEnd).not.toBeNull();
expect(item3IconStart).not.toBeNull();
expect(item3IconEnd).not.toBeNull();
expect(item4IconStart).toBeNull();
expect(item4IconEnd).toBeNull();
});
it("renders group title if specified and not if absent", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-dropdown>
<calcite-button slot="dropdown-trigger">Open dropdown</calcite-button>
<calcite-dropdown-group id="group-1" group-title="My Group 1 Title">
<calcite-dropdown-item id="item-1"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-2" active> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
<calcite-dropdown-group id="group-2">
<calcite-dropdown-item id="item-3"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-4" active> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>`);
const group1Title = await page.find("calcite-dropdown-group[id='group-1'] >>> .dropdown-title");
const group2Title = await page.find("calcite-dropdown-group[id='group-2'] >>> .dropdown-title");
expect(group1Title).not.toBeNull();
expect(group2Title).toBeNull();
});
it("renders active item based on attribute in dom", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-dropdown>
<calcite-button slot="dropdown-trigger">Open dropdown</calcite-button>
<calcite-dropdown-group id="group-1">
<calcite-dropdown-item id="item-1"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-2" active> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-3"> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>`);
const element = await page.find("calcite-dropdown");
const item1 = await element.find("calcite-dropdown-item[id='item-1']");
const item2 = await element.find("calcite-dropdown-item[id='item-2']");
const item3 = await element.find("calcite-dropdown-item[id='item-3']");
expect(item1).not.toHaveAttribute("active");
expect(item2).toHaveAttribute("active");
expect(item3).not.toHaveAttribute("active");
});
it("renders multiple active items when group is in multi selection mode", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-dropdown>
<calcite-button id="trigger" slot="dropdown-trigger">Open dropdown</calcite-button>
<calcite-dropdown-group id="group-1" selection-mode="multi">
<calcite-dropdown-item id="item-1"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-2" active> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-3"> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>`);
const element = await page.find("calcite-dropdown");
const trigger = await element.find("#trigger");
const group1 = await element.find("calcite-dropdown-group[id='group-1']");
const item1 = await element.find("calcite-dropdown-item[id='item-1']");
const item2 = await element.find("calcite-dropdown-item[id='item-2']");
const item3 = await element.find("calcite-dropdown-item[id='item-3']");
const itemChangeSpy = await element.spyOnEvent("calciteDropdownSelect");
expect(group1).toEqualAttribute("selection-mode", "multi");
await trigger.click();
await page.waitForChanges();
await assertSelectedItems(page, ["item-2"]);
await item1.click();
await page.waitForChanges();
await assertSelectedItems(page, ["item-1", "item-2"]);
await trigger.click();
await page.waitForChanges();
await item2.click();
await page.waitForChanges();
await assertSelectedItems(page, ["item-1"]);
await trigger.click();
await page.waitForChanges();
await item3.click();
await page.waitForChanges();
await assertSelectedItems(page, ["item-1", "item-3"]);
expect(item1).toHaveAttribute("active");
expect(item2).not.toHaveAttribute("active");
expect(item3).toHaveAttribute("active");
expect(itemChangeSpy).toHaveReceivedEventTimes(3);
});
it("renders just one active item when group is in single selection mode", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-dropdown>
<calcite-button id="trigger" slot="dropdown-trigger">Open dropdown</calcite-button>
<calcite-dropdown-group id="group-1" selection-mode="single">
<calcite-dropdown-item id="item-1"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-2" active> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-3"> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>`);
const element = await page.find("calcite-dropdown");
const trigger = await element.find("#trigger");
const group1 = await element.find("calcite-dropdown-group[id='group-1']");
const item1 = await element.find("calcite-dropdown-item[id='item-1']");
const item2 = await element.find("calcite-dropdown-item[id='item-2']");
const item3 = await element.find("calcite-dropdown-item[id='item-3']");
const itemChangeSpy = await element.spyOnEvent("calciteDropdownSelect");
expect(group1).toEqualAttribute("selection-mode", "single");
await assertSelectedItems(page, ["item-2"]);
await trigger.click();
await page.waitForChanges();
await item1.click();
await page.waitForChanges();
await assertSelectedItems(page, ["item-1"]);
await trigger.click();
await page.waitForChanges();
await item3.click();
await page.waitForChanges();
await assertSelectedItems(page, ["item-3"]);
expect(item1).not.toHaveAttribute("active");
expect(item2).not.toHaveAttribute("active");
expect(item3).toHaveAttribute("active");
expect(itemChangeSpy).toHaveReceivedEventTimes(2);
});
it("renders no active item when group is in none selection mode (and removes any active state set in dom on load)", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-dropdown>
<calcite-button id="trigger" slot="dropdown-trigger">Open dropdown</calcite-button>
<calcite-dropdown-group id="group-1" selection-mode="none">
<calcite-dropdown-item id="item-1"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-2" active> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-3"> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>`);
const element = await page.find("calcite-dropdown");
const trigger = await element.find("#trigger");
const group1 = await element.find("calcite-dropdown-group[id='group-1']");
const item1 = await element.find("calcite-dropdown-item[id='item-1']");
const item2 = await element.find("calcite-dropdown-item[id='item-2']");
const item3 = await element.find("calcite-dropdown-item[id='item-3']");
const itemChangeSpy = await element.spyOnEvent("calciteDropdownSelect");
expect(group1).toEqualAttribute("selection-mode", "none");
await assertSelectedItems(page, []);
await trigger.click();
await item1.click();
await page.waitForChanges();
await assertSelectedItems(page, []);
await trigger.click();
await item2.click();
await page.waitForChanges();
await assertSelectedItems(page, []);
await trigger.click();
await item3.click();
await page.waitForChanges();
await assertSelectedItems(page, []);
expect(item1).not.toHaveAttribute("active");
expect(item2).not.toHaveAttribute("active");
expect(item3).not.toHaveAttribute("active");
expect(itemChangeSpy).toHaveReceivedEventTimes(3);
});
it("renders the correct active state when parent contains groups of assorted selection modes", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-dropdown>
<calcite-button slot="dropdown-trigger" id="trigger">Open dropdown</calcite-button>
<calcite-dropdown-group id="group-1" selection-mode="multi">
<calcite-dropdown-item id="item-1"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-2" active> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-3"> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
<calcite-dropdown-group id="group-2" selection-mode="single">
<calcite-dropdown-item id="item-4"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-5" active> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-6"> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
<calcite-dropdown-group id="group-3" selection-mode="none">
<calcite-dropdown-item id="item-7"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-8"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-9"> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>`);
const element = await page.find("calcite-dropdown");
const trigger = await element.find("#trigger");
const group1 = await element.find("calcite-dropdown-group[id='group-1']");
const group2 = await element.find("calcite-dropdown-group[id='group-2']");
const group3 = await element.find("calcite-dropdown-group[id='group-3']");
const item1 = await element.find("calcite-dropdown-item[id='item-1']");
const item2 = await element.find("calcite-dropdown-item[id='item-2']");
const item3 = await element.find("calcite-dropdown-item[id='item-3']");
const item4 = await element.find("calcite-dropdown-item[id='item-4']");
const item5 = await element.find("calcite-dropdown-item[id='item-5']");
const item6 = await element.find("calcite-dropdown-item[id='item-6']");
const item7 = await element.find("calcite-dropdown-item[id='item-7']");
const item8 = await element.find("calcite-dropdown-item[id='item-8']");
const item9 = await element.find("calcite-dropdown-item[id='item-9']");
const itemChangeSpy = await element.spyOnEvent("calciteDropdownSelect");
expect(group1).toEqualAttribute("selection-mode", "multi");
expect(group2).toEqualAttribute("selection-mode", "single");
expect(group3).toEqualAttribute("selection-mode", "none");
await assertSelectedItems(page, ["item-2", "item-5"]);
await trigger.click();
await page.waitForChanges();
await item1.click();
await page.waitForChanges();
await assertSelectedItems(page, ["item-1", "item-2", "item-5"]);
await trigger.click();
await page.waitForChanges();
await item2.click();
await page.waitForChanges();
await assertSelectedItems(page, ["item-1", "item-5"]);
await trigger.click();
await page.waitForChanges();
await item3.click();
await page.waitForChanges();
await assertSelectedItems(page, ["item-1", "item-3", "item-5"]);
await trigger.click();
await page.waitForChanges();
await item4.click();
await page.waitForChanges();
await assertSelectedItems(page, ["item-1", "item-3", "item-4"]);
await trigger.click();
await page.waitForChanges();
await item6.click();
await page.waitForChanges();
await assertSelectedItems(page, ["item-1", "item-3", "item-6"]);
await trigger.click();
await page.waitForChanges();
await item7.click();
await page.waitForChanges();
await assertSelectedItems(page, ["item-1", "item-3", "item-6"]);
await trigger.click();
await page.waitForChanges();
await item9.click();
await page.waitForChanges();
await assertSelectedItems(page, ["item-1", "item-3", "item-6"]);
expect(item1).toHaveAttribute("active");
expect(item2).not.toHaveAttribute("active");
expect(item3).toHaveAttribute("active");
expect(item4).not.toHaveAttribute("active");
expect(item5).not.toHaveAttribute("active");
expect(item6).toHaveAttribute("active");
expect(item7).not.toHaveAttribute("active");
expect(item8).not.toHaveAttribute("active");
expect(item9).not.toHaveAttribute("active");
expect(itemChangeSpy).toHaveReceivedEventTimes(7);
});
it("renders a calcite-dropdown-item with child anchor link with passed attributes if href is present", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-dropdown>
<calcite-button id="trigger" slot="dropdown-trigger">Open dropdown</calcite-button>
<calcite-dropdown-group id="group-1" selection-mode="none">
<calcite-dropdown-item id="item-1"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-2" href="google.com" rel="noopener noreferrer" target="_blank">
Dropdown Item Content
</calcite-dropdown-item>
<calcite-dropdown-item id="item-3"> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>`);
const elementAsLink = await page.find("calcite-dropdown-item[id='item-2'] >>> a");
expect(elementAsLink).not.toBeNull();
expect(elementAsLink).toEqualAttribute("href", "google.com");
expect(elementAsLink).toEqualAttribute("rel", "noopener noreferrer");
expect(elementAsLink).toEqualAttribute("target", "_blank");
});
it("should focus the first item on open when there is no active item", async () => {
const page = await newE2EPage({
html: html`<calcite-dropdown>
<calcite-button slot="dropdown-trigger">Open Dropdown</calcite-button>
<calcite-dropdown-group>
<calcite-dropdown-item id="item-1">1</calcite-dropdown-item>
<calcite-dropdown-item id="item-2">2</calcite-dropdown-item>
<calcite-dropdown-item id="item-3">3</calcite-dropdown-item>
<calcite-dropdown-item id="item-4">4</calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>`
});
const element = await page.find("calcite-dropdown");
const dropdownOpenEvent = page.waitForEvent("calciteDropdownOpen");
element.click();
await dropdownOpenEvent;
expect(await page.evaluate(() => document.activeElement.id)).toEqual("item-1");
});
it("should focus the first active item on open", async () => {
const page = await newE2EPage({
html: html`<calcite-dropdown>
<calcite-button slot="dropdown-trigger">Open Dropdown</calcite-button>
<calcite-dropdown-group>
<calcite-dropdown-item id="item-1">1</calcite-dropdown-item>
<calcite-dropdown-item id="item-2">2</calcite-dropdown-item>
<calcite-dropdown-item id="item-3" active>3</calcite-dropdown-item>
<calcite-dropdown-item id="item-4">4</calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>`
});
const element = await page.find("calcite-dropdown");
const dropdownOpenEvent = page.waitForEvent("calciteDropdownOpen");
element.click();
await dropdownOpenEvent;
expect(await page.evaluate(() => document.activeElement.id)).toEqual("item-3");
});
it("should focus the first active item on open (multi)", async () => {
const page = await newE2EPage({
html: html`<calcite-dropdown>
<calcite-button slot="dropdown-trigger">Open Dropdown</calcite-button>
<calcite-dropdown-group selection-mode="multi">
<calcite-dropdown-item id="item-1">1</calcite-dropdown-item>
<calcite-dropdown-item id="item-2" active>2</calcite-dropdown-item>
<calcite-dropdown-item id="item-3">3</calcite-dropdown-item>
<calcite-dropdown-item id="item-4" active>4</calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>`
});
const element = await page.find("calcite-dropdown");
const dropdownOpenEvent = page.waitForEvent("calciteDropdownOpen");
element.click();
await dropdownOpenEvent;
expect(await page.evaluate(() => document.activeElement.id)).toEqual("item-2");
});
describe("scrolling", () => {
it("focused item should be in view when long", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-dropdown>
<calcite-button slot="dropdown-trigger">Open Dropdown</calcite-button>
<calcite-dropdown-group>
<calcite-dropdown-item id="item-1">1</calcite-dropdown-item>
<calcite-dropdown-item id="item-2">2</calcite-dropdown-item>
<calcite-dropdown-item id="item-3">3</calcite-dropdown-item>
<calcite-dropdown-item id="item-4">4</calcite-dropdown-item>
<calcite-dropdown-item id="item-5">5</calcite-dropdown-item>
<calcite-dropdown-item id="item-6">6</calcite-dropdown-item>
<calcite-dropdown-item id="item-7">7</calcite-dropdown-item>
<calcite-dropdown-item id="item-8">8</calcite-dropdown-item>
<calcite-dropdown-item id="item-9">9</calcite-dropdown-item>
<calcite-dropdown-item id="item-10">10</calcite-dropdown-item>
<calcite-dropdown-item id="item-11">11</calcite-dropdown-item>
<calcite-dropdown-item id="item-12">12</calcite-dropdown-item>
<calcite-dropdown-item id="item-13">13</calcite-dropdown-item>
<calcite-dropdown-item id="item-14">14</calcite-dropdown-item>
<calcite-dropdown-item id="item-15">15</calcite-dropdown-item>
<calcite-dropdown-item id="item-16">16</calcite-dropdown-item>
<calcite-dropdown-item id="item-17">17</calcite-dropdown-item>
<calcite-dropdown-item id="item-18">18</calcite-dropdown-item>
<calcite-dropdown-item id="item-19">19</calcite-dropdown-item>
<calcite-dropdown-item id="item-20">20</calcite-dropdown-item>
<calcite-dropdown-item id="item-21">21</calcite-dropdown-item>
<calcite-dropdown-item id="item-22">22</calcite-dropdown-item>
<calcite-dropdown-item id="item-23">23</calcite-dropdown-item>
<calcite-dropdown-item id="item-24">24</calcite-dropdown-item>
<calcite-dropdown-item id="item-25">25</calcite-dropdown-item>
<calcite-dropdown-item id="item-26">26</calcite-dropdown-item>
<calcite-dropdown-item id="item-27">27</calcite-dropdown-item>
<calcite-dropdown-item id="item-28">28</calcite-dropdown-item>
<calcite-dropdown-item id="item-29">29</calcite-dropdown-item>
<calcite-dropdown-item id="item-30">30</calcite-dropdown-item>
<calcite-dropdown-item id="item-41">41</calcite-dropdown-item>
<calcite-dropdown-item id="item-42">42</calcite-dropdown-item>
<calcite-dropdown-item id="item-43">43</calcite-dropdown-item>
<calcite-dropdown-item id="item-44">44</calcite-dropdown-item>
<calcite-dropdown-item id="item-45">45</calcite-dropdown-item>
<calcite-dropdown-item id="item-46">46</calcite-dropdown-item>
<calcite-dropdown-item id="item-47">47</calcite-dropdown-item>
<calcite-dropdown-item id="item-48">48</calcite-dropdown-item>
<calcite-dropdown-item id="item-49">49</calcite-dropdown-item>
<calcite-dropdown-item id="item-50" active>50</calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>`);
await page.waitForChanges();
const element = await page.find("calcite-dropdown");
const dropdownOpenEvent = page.waitForEvent("calciteDropdownOpen");
element.click();
await dropdownOpenEvent;
expect(await page.evaluate(() => document.activeElement.id)).toEqual("item-50");
const item = await page.find("#item-50");
expect(await item.isIntersectingViewport()).toBe(true);
});
it("control max items displayed", async () => {
const maxItems = 7;
const page = await newE2EPage({
html: html`<calcite-dropdown max-items="${maxItems}">
<calcite-button slot="dropdown-trigger">Open Dropdown</calcite-button>
<calcite-dropdown-group group-title="First group">
<calcite-dropdown-item id="item-1">1</calcite-dropdown-item>
<calcite-dropdown-item id="item-2">2</calcite-dropdown-item>
<calcite-dropdown-item id="item-3">3</calcite-dropdown-item>
<calcite-dropdown-item id="item-4">4</calcite-dropdown-item>
<calcite-dropdown-item id="item-5">5</calcite-dropdown-item>
</calcite-dropdown-group>
<calcite-dropdown-group group-title="Second group">
<calcite-dropdown-item id="item-6">6</calcite-dropdown-item>
<calcite-dropdown-item id="item-7">7</calcite-dropdown-item>
<calcite-dropdown-item id="item-8">8</calcite-dropdown-item>
<calcite-dropdown-item id="item-9">9</calcite-dropdown-item>
<calcite-dropdown-item id="item-10">10</calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>`
});
const element = await page.find("calcite-dropdown");
const dropdownOpenEvent = page.waitForEvent("calciteDropdownOpen");
element.click();
await dropdownOpenEvent;
const items = await page.findAll("calcite-dropdown-item");
for (let i = 0; i < items.length; i++) {
expect(await items[i].isIntersectingViewport()).toBe(i <= maxItems - 1);
}
const newMaxItems = 4;
element.setProperty("maxItems", newMaxItems);
await page.waitForChanges();
for (let i = 0; i < items.length; i++) {
expect(await items[i].isIntersectingViewport()).toBe(i <= newMaxItems - 1);
}
});
});
it("closes when a selection is made", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-dropdown>
<calcite-button id="trigger" slot="dropdown-trigger">Open dropdown</calcite-button>
<calcite-dropdown-group id="group-1" selection-mode="single">
<calcite-dropdown-item id="item-1"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-2" active> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-3"> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>`);
const element = await page.find("calcite-dropdown");
const trigger = await element.find("#trigger");
const item1 = await element.find("calcite-dropdown-item[id='item-1']");
const dropdownWrapper = await page.find("calcite-dropdown >>> .calcite-dropdown-wrapper");
expect(await dropdownWrapper.isVisible()).toBe(false);
await trigger.click();
await page.waitForChanges();
expect(await dropdownWrapper.isVisible()).toBe(true);
await item1.click();
await page.waitForChanges();
expect(await dropdownWrapper.isVisible()).toBe(false);
});
it("remains open when disable-close-on-select is requested and selected item is not in a selection-mode:none group", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-dropdown disable-close-on-select>
<calcite-button id="trigger" slot="dropdown-trigger">Open dropdown</calcite-button>
<calcite-dropdown-group id="group-1" selection-mode="single">
<calcite-dropdown-item id="item-1"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-2" active> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item>
<div id="item-3">Dropdown Item Content</div>
</calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>`);
const element = await page.find("calcite-dropdown");
const trigger = await element.find("#trigger");
const item1 = await element.find("#item-1");
const item3 = await element.find("#item-3");
const dropdownWrapper = await page.find("calcite-dropdown >>> .calcite-dropdown-wrapper");
expect(await dropdownWrapper.isVisible()).toBe(false);
await trigger.click();
await page.waitForChanges();
expect(await dropdownWrapper.isVisible()).toBe(true);
await item1.click();
await page.waitForChanges();
expect(await dropdownWrapper.isVisible()).toBe(true);
await item3.click();
await page.waitForChanges();
expect(await dropdownWrapper.isVisible()).toBe(true);
});
it("closes when disable-close-on-select is requested and selected item is in a selection-mode:none group", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-dropdown disable-close-on-select>
<calcite-button id="trigger" slot="dropdown-trigger">Open dropdown</calcite-button>
<calcite-dropdown-group id="group-1" selection-mode="none">
<calcite-dropdown-item>
<div id="item-1">Dropdown Item Content</div>
</calcite-dropdown-item>
<calcite-dropdown-item id="item-2"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-3"> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>`);
const element = await page.find("calcite-dropdown");
const trigger = await element.find("#trigger");
const item1 = await element.find("#item-1");
const dropdownWrapper = await page.find("calcite-dropdown >>> .calcite-dropdown-wrapper");
expect(await dropdownWrapper.isVisible()).toBe(false);
await trigger.click();
await page.waitForChanges();
expect(await dropdownWrapper.isVisible()).toBe(true);
await item1.click();
await page.waitForChanges();
expect(await dropdownWrapper.isVisible()).toBe(false);
});
describe("toggles the dropdown with click, enter, or space", () => {
it("toggles when dropdown-trigger is a button", async () => {
const page = await newE2EPage();
await page.setContent(html`
<calcite-dropdown>
<calcite-button slot="dropdown-trigger">Open dropdown</calcite-button>
<calcite-dropdown-group selection-mode="single">
<calcite-dropdown-item id="item-1"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-2" active> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>
`);
const element = await page.find("calcite-dropdown");
const trigger = await element.find("calcite-button[slot='dropdown-trigger']");
const dropdownWrapper = await page.find(`calcite-dropdown >>> .calcite-dropdown-wrapper`);
const calciteDropdownOpen = await element.spyOnEvent("calciteDropdownOpen");
const calciteDropdownClose = await element.spyOnEvent("calciteDropdownClose");
let waitForCalciteDropdownOpen = page.waitForEvent("calciteDropdownOpen");
const waitForCalciteDropdownClose = page.waitForEvent("calciteDropdownClose");
expect(await dropdownWrapper.isVisible()).toBe(false);
await trigger.click();
await page.waitForChanges();
expect(await dropdownWrapper.isVisible()).toBe(true);
await waitForCalciteDropdownOpen;
expect(calciteDropdownOpen).toHaveReceivedEventTimes(1);
expect(calciteDropdownClose).toHaveReceivedEventTimes(0);
await trigger.focus();
await page.keyboard.press("Space");
await page.waitForChanges();
expect(await dropdownWrapper.isVisible()).toBe(false);
await waitForCalciteDropdownClose;
expect(calciteDropdownOpen).toHaveReceivedEventTimes(1);
expect(calciteDropdownClose).toHaveReceivedEventTimes(1);
waitForCalciteDropdownOpen = page.waitForEvent("calciteDropdownOpen");
await page.keyboard.press("Enter");
await page.waitForChanges();
expect(await dropdownWrapper.isVisible()).toBe(true);
await waitForCalciteDropdownOpen;
expect(calciteDropdownOpen).toHaveReceivedEventTimes(2);
expect(calciteDropdownClose).toHaveReceivedEventTimes(1);
});
it("toggle when dropdown-trigger is an action", async () => {
const page = await newE2EPage();
await page.setContent(html`
<calcite-dropdown>
<calcite-action slot="dropdown-trigger">Open dropdown</calcite-action>
<calcite-dropdown-group selection-mode="single">
<calcite-dropdown-item id="item-1"> Dropdown Item Content</calcite-dropdown-item>
<calcite-dropdown-item id="item-2" active> Dropdown Item Content</calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>
`);
const element = await page.find("calcite-dropdown");
const trigger = await element.find("calcite-action[slot='dropdown-trigger'] >>> button");
const dropdownWrapper = await page.find(`calcite-dropdown >>> .calcite-dropdown-wrapper`);
const calciteDropdownOpen = await element.spyOnEvent("calciteDropdownOpen");
const calciteDropdownClose = await element.spyOnEvent("calciteDropdownClose");
let waitForCalciteDropdownOpen = page.waitForEvent("calciteDropdownOpen");
const waitForCalciteDropdownClose = page.waitForEvent("calciteDropdownClose");
expect(await dropdownWrapper.isVisible()).toBe(false);
await trigger.click();
await page.waitForChanges();
expect(await dropdownWrapper.isVisible()).toBe(true);
await waitForCalciteDropdownOpen;
expect(calciteDropdownOpen).toHaveReceivedEventTimes(1);
expect(calciteDropdownClose).toHaveReceivedEventTimes(0);
await trigger.focus();
await page.keyboard.press("Space");
await page.waitForChanges();
expect(await dropdownWrapper.isVisible()).toBe(false);
await waitForCalciteDropdownClose;
expect(calciteDropdownOpen).toHaveReceivedEventTimes(1);
expect(calciteDropdownClose).toHaveReceivedEventTimes(1);
waitForCalciteDropdownOpen = page.waitForEvent("calciteDropdownOpen");
await page.keyboard.press("Enter");
await page.waitForChanges();
expect(await dropdownWrapper.isVisible()).toBe(true);
await waitForCalciteDropdownOpen;
expect(calciteDropdownOpen).toHaveReceivedEventTimes(2);
expect(calciteDropdownClose).toHaveReceivedEventTimes(1);
});
});
it("closes existing open dropdown when opened", async () => {
const page = await newE2EPage();
await page.setContent(html` <calcite-dropdown id="dropdown-1">
<calcite-button id="trigger" slot="dropdown-trigger">Open dropdown</calcite-button>
<calcite-dropdown-group id="group-1" selection-mode="single">
<calcite-dropdown-item id="item-1"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-2" active> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-3"> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>
<calcite-dropdown id="dropdown-2">
<calcite-button id="trigger" slot="dropdown-trigger">Open dropdown</calcite-button>
<calcite-dropdown-group id="group-1" selection-mode="single">
<calcite-dropdown-item id="item-1"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-2" active> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-3"> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>`);
const element1 = await page.find("calcite-dropdown[id='dropdown-1']");
const element2 = await page.find("calcite-dropdown[id='dropdown-2']");
const trigger1 = await element1.find("#trigger");
const trigger2 = await element2.find("#trigger");
const dropdownWrapper1 = await page.find("calcite-dropdown[id='dropdown-1'] >>> .calcite-dropdown-wrapper");
const dropdownWrapper2 = await page.find("calcite-dropdown[id='dropdown-2'] >>> .calcite-dropdown-wrapper");
expect(await dropdownWrapper1.isVisible()).toBe(false);
expect(await dropdownWrapper2.isVisible()).toBe(false);
await trigger1.click();
await page.waitForChanges();
expect(await dropdownWrapper1.isVisible()).toBe(true);
expect(await dropdownWrapper2.isVisible()).toBe(false);
await trigger2.click();
await page.waitForChanges();
expect(await dropdownWrapper1.isVisible()).toBe(false);
expect(await dropdownWrapper2.isVisible()).toBe(true);
});
it("focus is returned to trigger after close", async () => {
const page = await newE2EPage();
await page.setContent(html`
<calcite-dropdown>
<calcite-button id="trigger" slot="dropdown-trigger">Open dropdown</calcite-button>
<calcite-dropdown-group id="group-1" selection-mode="single">
<calcite-dropdown-item id="item-1"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-2" active> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-3"> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>
`);
const element = await page.find("calcite-dropdown");
const trigger = await element.find("#trigger");
const item1 = await element.find("calcite-dropdown-item[id='item-1']");
const dropdownWrapper = await page.find("calcite-dropdown >>> .calcite-dropdown-wrapper");
expect(await dropdownWrapper.isVisible()).toBe(false);
await trigger.click();
await page.waitForChanges();
expect(await dropdownWrapper.isVisible()).toBe(true);
await item1.click();
await page.waitForChanges();
expect(await dropdownWrapper.isVisible()).toBe(false);
expect(await page.evaluate(() => document.activeElement.id)).toEqual("trigger");
});
it("accepts multiple triggers", async () => {
const page = await newE2EPage();
await page.setContent(html`
<calcite-dropdown>
<calcite-button class="trigger" slot="dropdown-trigger">Open dropdown</calcite-button>
<calcite-icon class="trigger" icon="caretDown" scale="s" slot="dropdown-trigger"></calcite-icon>
<calcite-dropdown-group id="group-1" selection-mode="single">
<calcite-dropdown-item id="item-1"> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-2" active> Dropdown Item Content </calcite-dropdown-item>
<calcite-dropdown-item id="item-3"> Dropdown Item Content </calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>
`);
const element = await page.find("calcite-dropdown");
const trigger = await element.findAll(".trigger");
const dropdownWrapper = await page.find("calcite-dropdown >>> .calcite-dropdown-wrapper");
await trigger[0].click();
expect(await dropdownWrapper.isVisible()).toBe(true);
await trigger[0].click();
await page.waitForChanges();
expect(await dropdownWrapper.isVisible()).toBe(false);
await page.waitForChanges();
await trigger[1].click();
expect(await dropdownWrapper.isVisible()).toBe(true);
await trigger[1].click();
await page.waitForChanges();
expect(await dropdownWrapper.isVisible()).toBe(false);
});
it("is accessible", async () => {
await accessible(dedent`${dropdownSelectionModeContent}`);
});
it("correct role and aria properties are applied based on selection type", async () => {
const page = await newE2EPage();
await page.setContent(dedent`${dropdownSelectionModeContent}`);
await page.waitForChanges();
const element = await page.find("calcite-dropdown");
const group1 = await element.find("calcite-dropdown-group[id='group-1']");
const group2 = await element.find("calcite-dropdown-group[id='group-2']");
const group3 = await element.find("calcite-dropdown-group[id='group-3']");
const item1 = await element.find("calcite-dropdown-item[id='item-1']");
const item2 = await element.find("calcite-dropdown-item[id='item-2']");
const item3 = await element.find("calcite-dropdown-item[id='item-3']");
const item4 = await element.find("calcite-dropdown-item[id='item-4']");
const item5 = await element.find("calcite-dropdown-item[id='item-5']");
const item6 = await element.find("calcite-dropdown-item[id='item-6']");
const item7 = await element.find("calcite-dropdown-item[id='item-7']");
expect(group1).toEqualAttribute("role", "menu");
expect(group2).toEqualAttribute("role", "menu");
expect(group3).toEqualAttribute("role", "menu");
expect(item1).toEqualAttribute("role", "menuitemcheckbox");
expect(item1).toEqualAttribute("aria-checked", "false");
expect(item2).toEqualAttribute("role", "menuitemcheckbox");
expect(item2).toEqualAttribute("aria-checked", "true");
expect(item3).toEqualAttribute("role", "menuitemcheckbox");
expect(item3).toEqualAttribute("aria-checked", "true");
expect(item4).toEqualAttribute("role", "menuitemradio");
expect(item4).toEqualAttribute("aria-checked", "false");
expect(item5).toEqualAttribute("role", "menuitemradio");
expect(item5).toEqualAttribute("aria-checked", "true");
expect(item6).toEqualAttribute("role", "menuitem");
expect(item6).not.toHaveAttribute("aria-checked");
expect(item7).not.toHaveAttribute("role");
expect(item7).not.toHaveAttribute("aria-checked");
});
it("item selection should work when placed inside shadow DOM (#992)", async () => {
const wrappedDropdownTemplateHTML = html`
<calcite-dropdown disable-close-on-select>
<calcite-button slot="dropdown-trigger">Open</calcite-button>
<calcite-dropdown-group selection-mode="single">
<calcite-dropdown-item id="item-1" active>1</calcite-dropdown-item>
<calcite-dropdown-item id="item-2">2</calcite-dropdown-item>
<calcite-dropdown-item id="item-3">3</calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>
`;
const page = await newE2EPage({
// load page with the dropdown template,
// so they're available in the browser-evaluated fn below
html: wrappedDropdownTemplateHTML
});
await page.waitForChanges();
const finalSelectedItem = await page.evaluate(
async (templateHTML: string): Promise<string> => {
const wrapperName = "dropdown-wrapping-component";
customElements.define(
wrapperName,
class extends HTMLElement {
constructor() {
super();
}
connectedCallback(): void {
this.attachShadow({ mode: "open" }).innerHTML = templateHTML;
}
}
);
document.body.innerHTML = `<${wrapperName}></${wrapperName}>`;
const wrapper = document.querySelector(wrapperName);
wrapper.shadowRoot.querySelector<HTMLElement>("#item-3").click();
await new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));
await new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));
return wrapper.shadowRoot.querySelector("calcite-dropdown-item[active]").id;
},
[wrappedDropdownTemplateHTML]
);
expect(finalSelectedItem).toBe("item-3");
});
it("dropdown should not overflow when wrapped inside a tab #3007", async () => {
const page = await newE2EPage({
html: html`<calcite-tabs>
<calcite-tab-nav slot="tab-nav">
<calcite-tab-title is-active>First tab</calcite-tab-title>
</calcite-tab-nav>
<calcite-tab is-active>
<calcite-dropdown>
<calcite-button slot="dropdown-trigger" class="dropdown">Dropdown</calcite-button>
<calcite-dropdown-group group-title="Select one">
<calcite-dropdown-item>First</calcite-dropdown-item>
<calcite-dropdown-item>Second</calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>
</calcite-tab>
</calcite-tabs>`
});
await page.waitForChanges();
const button = await page.find("calcite-button");
await button.click();
await page.waitForChanges();
expect(
await page.$eval("calcite-dropdown", (dropdown) => {
// check whether the element is overflown, ref :https://stackoverflow.com/questions/9333379/check-if-an-elements-content-is-overflowing
const { clientWidth, clientHeight, scrollWidth, scrollHeight } = dropdown;
return scrollHeight > clientHeight || scrollWidth > clientWidth;
})
).toBe(false);
});
it("dropdown wrapper shouldn't have height when filter results empty and combined with a PickList in Panel #3048", async () => {
const page = await newE2EPage({
html: html`<calcite-panel heading="Issue #3048">
<calcite-pick-list filter-enabled>
<calcite-dropdown slot="menu-actions" placement="bottom-trailing" type="click">
<calcite-action slot="dropdown-trigger" title="Sort" icon="sort-descending"> </calcite-action>
<calcite-dropdown-group selection-mode="single">
<calcite-dropdown-item>Display name</calcite-dropdown-item>
<calcite-dropdown-item>Type</calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>
<calcite-pick-list-item label="calcite" description="calcite!"> </calcite-pick-list-item>
<calcite-pick-list-item label="calcite" description="calcite"> </calcite-pick-list-item>
</calcite-pick-list>
</calcite-panel>`
});
await page.waitForChanges();
const dropdownContentHeight = await (