@spectrum-web-components/picker 0.14.2-overlay.33 → 0.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/test/index.js CHANGED
@@ -29,9 +29,9 @@ import { sendMouse } from "../../../test/plugins/browser.js";
29
29
  import { ignoreResizeObserverLoopError } from "../../../test/testing-helpers.js";
30
30
  import { isWebKit } from "@spectrum-web-components/shared/src/platform.js";
31
31
  ignoreResizeObserverLoopError(before, after);
32
- const isMenuActiveElement = function(el) {
32
+ const isMenuActiveElement = function() {
33
33
  var _a;
34
- return ((_a = el.shadowRoot.activeElement) == null ? void 0 : _a.localName) === "sp-menu";
34
+ return ((_a = document.activeElement) == null ? void 0 : _a.localName) === "sp-menu";
35
35
  };
36
36
  export function runPickerTests() {
37
37
  let el;
@@ -81,7 +81,7 @@ export function runPickerTests() {
81
81
  el.open = true;
82
82
  await opened;
83
83
  expect(el.open).to.be.true;
84
- const accessibleCloseButton = el.shadowRoot.querySelector(
84
+ const accessibleCloseButton = document.querySelector(
85
85
  ".visually-hidden button"
86
86
  );
87
87
  const closed = oneEvent(el, "sp-closed");
@@ -90,7 +90,6 @@ export function runPickerTests() {
90
90
  expect(el.open).to.be.false;
91
91
  });
92
92
  it("accepts new selected item content", async () => {
93
- await nextFrame();
94
93
  const option2 = el.querySelector('[value="option-2"');
95
94
  el.value = "option-2";
96
95
  await elementUpdated(option2);
@@ -115,7 +114,6 @@ export function runPickerTests() {
115
114
  expect((el.button.textContent || "").trim()).to.equal(newLabel2);
116
115
  });
117
116
  it("accepts new selected item content when open", async () => {
118
- await nextFrame();
119
117
  const option2 = el.querySelector('[value="option-2"');
120
118
  el.value = "option-2";
121
119
  await elementUpdated(el);
@@ -139,7 +137,6 @@ export function runPickerTests() {
139
137
  );
140
138
  });
141
139
  it("unsets value when children removed", async () => {
142
- await nextFrame();
143
140
  el.value = "option-2";
144
141
  await elementUpdated(el);
145
142
  expect(el.value).to.equal("option-2");
@@ -155,8 +152,6 @@ export function runPickerTests() {
155
152
  });
156
153
  await Promise.all(removals);
157
154
  await elementUpdated(el);
158
- await nextFrame();
159
- expect(el.optionsMenu.childItems.length).to.equal(0);
160
155
  expect(el.value).to.equal("");
161
156
  expect((el.button.textContent || "").trim()).to.equal("");
162
157
  });
@@ -168,7 +163,7 @@ export function runPickerTests() {
168
163
  item.value = "option-new";
169
164
  item.textContent = "New Option";
170
165
  el.append(item);
171
- await nextFrame();
166
+ await elementUpdated(el);
172
167
  el.value = "option-new";
173
168
  await elementUpdated(el);
174
169
  expect(el.value).to.equal("option-new");
@@ -181,7 +176,8 @@ export function runPickerTests() {
181
176
  item.value = "option-new";
182
177
  item.textContent = "New Option";
183
178
  el.append(item);
184
- await nextFrame();
179
+ await elementUpdated(item);
180
+ await elementUpdated(el);
185
181
  let opened = oneEvent(el, "sp-opened");
186
182
  el.open = true;
187
183
  await opened;
@@ -198,7 +194,6 @@ export function runPickerTests() {
198
194
  expect(el.value, "second time").to.equal("option-new");
199
195
  });
200
196
  it('manages its "name" value in the accessibility tree', async () => {
201
- await nextFrame();
202
197
  let snapshot = await a11ySnapshot({});
203
198
  expect(
204
199
  findAccessibilityNode(
@@ -209,7 +204,6 @@ export function runPickerTests() {
209
204
  ).to.not.be.null;
210
205
  el.value = "option-2";
211
206
  await elementUpdated(el);
212
- await nextFrame();
213
207
  snapshot = await a11ySnapshot({});
214
208
  expect(
215
209
  findAccessibilityNode(
@@ -245,7 +239,7 @@ export function runPickerTests() {
245
239
  await elementUpdated(el);
246
240
  await expect(el).to.be.accessible();
247
241
  });
248
- xit("opens with visible focus on a menu item on `DownArrow`", async () => {
242
+ it("opens with visible focus on a menu item on `DownArrow`", async () => {
249
243
  const firstItem = el.querySelector("sp-menu-item");
250
244
  await elementUpdated(el);
251
245
  expect(firstItem.focused, "should not visually focused").to.be.false;
@@ -303,15 +297,11 @@ export function runPickerTests() {
303
297
  document.body.append(other);
304
298
  await elementUpdated(el);
305
299
  expect(el.open).to.be.false;
306
- const opened = oneEvent(el, "sp-opened");
307
300
  el.click();
308
- await opened;
309
301
  await elementUpdated(el);
310
302
  expect(el.open).to.be.true;
311
- const closed = oneEvent(el, "sp-closed");
312
303
  other.click();
313
- closed;
314
- await elementUpdated(el);
304
+ await waitUntil(() => !el.open, "closed");
315
305
  other.remove();
316
306
  });
317
307
  it("selects", async () => {
@@ -464,14 +454,18 @@ export function runPickerTests() {
464
454
  expect(el.open, "still closed").to.be.false;
465
455
  button.dispatchEvent(arrowUpEvent());
466
456
  await elementUpdated(el);
467
- const opened = oneEvent(el, "sp-opened");
468
457
  expect(el.open, "open by ArrowUp").to.be.true;
469
- await opened;
470
- const closed = oneEvent(el, "sp-closed");
458
+ await waitUntil(
459
+ () => document.querySelector("active-overlay") !== null,
460
+ "an active-overlay has been inserted on the page"
461
+ );
471
462
  button.dispatchEvent(escapeEvent());
472
- await closed;
473
463
  await elementUpdated(el);
474
464
  await waitUntil(() => el.open === false, "closed by Escape");
465
+ await waitUntil(
466
+ () => document.querySelector("active-overlay") === null,
467
+ "an active-overlay has been inserted on the page"
468
+ );
475
469
  });
476
470
  it("opens on ArrowDown", async () => {
477
471
  var _a, _b;
@@ -498,7 +492,6 @@ export function runPickerTests() {
498
492
  expect(el.value).to.equal("Deselect");
499
493
  });
500
494
  it("quick selects on ArrowLeft/Right", async () => {
501
- await nextFrame();
502
495
  const selectionSpy = spy();
503
496
  el.addEventListener("change", (event) => {
504
497
  const { value } = event.target;
@@ -526,7 +519,6 @@ export function runPickerTests() {
526
519
  expect(selectionSpy.calledWith("Make Work Path")).to.be.false;
527
520
  });
528
521
  it("quick selects first item on ArrowRight when no value", async () => {
529
- await nextFrame();
530
522
  const selectionSpy = spy();
531
523
  el.addEventListener("change", (event) => {
532
524
  const { value } = event.target;
@@ -544,10 +536,6 @@ export function runPickerTests() {
544
536
  });
545
537
  it("refocuses on list when open", async () => {
546
538
  const firstItem = el.querySelector("sp-menu-item");
547
- const thirdItem = el.querySelector(
548
- "sp-menu-item:nth-of-type(3)"
549
- );
550
- const button = el.button;
551
539
  const input = document.createElement("input");
552
540
  el.insertAdjacentElement("afterend", input);
553
541
  el.focus();
@@ -555,41 +543,44 @@ export function runPickerTests() {
555
543
  expect(document.activeElement === input).to.be.true;
556
544
  await sendKeys({ press: "Shift+Tab" });
557
545
  expect(document.activeElement === el).to.be.true;
546
+ await sendKeys({ press: "Enter" });
558
547
  const opened = oneEvent(el, "sp-opened");
559
- sendKeys({ press: "Enter" });
548
+ el.open = true;
560
549
  await opened;
561
550
  await elementUpdated(el);
562
551
  await waitUntil(
563
552
  () => firstItem.focused,
564
553
  "The first items should have become focused visually."
565
554
  );
566
- await sendKeys({ press: "ArrowDown" });
567
- await sendKeys({ press: "ArrowDown" });
568
- expect(thirdItem.focused).to.be.true;
569
- button.focus();
570
- expect(isMenuActiveElement(el)).to.be.false;
555
+ el.blur();
556
+ await elementUpdated(el);
557
+ expect(el.open).to.be.true;
571
558
  el.focus();
572
559
  await elementUpdated(el);
573
560
  await waitUntil(
574
- () => isMenuActiveElement(el),
561
+ () => isMenuActiveElement(),
575
562
  "first item refocused"
576
563
  );
577
- expect(isMenuActiveElement(el)).to.be.true;
578
- expect(thirdItem.focused).to.be.true;
564
+ expect(el.open).to.be.true;
565
+ expect(isMenuActiveElement()).to.be.true;
566
+ await sendKeys({ press: "ArrowDown" });
567
+ await sendKeys({ press: "ArrowUp" });
568
+ expect(firstItem.focused).to.be.true;
579
569
  });
580
- it("allows tabing to close", async () => {
581
- const input = document.createElement("input");
582
- el.insertAdjacentElement("afterend", input);
583
- const opened = oneEvent(el, "sp-opened");
570
+ it("does not allow tabing to close", async () => {
584
571
  el.open = true;
585
- await opened;
586
- await nextFrame();
572
+ await elementUpdated(el);
587
573
  expect(el.open).to.be.true;
588
574
  el.focus();
589
- const closed = oneEvent(el, "sp-closed");
590
- sendKeys({ press: "Tab" });
591
- await closed;
592
- expect(el.open, "closes").to.be.false;
575
+ await elementUpdated(el);
576
+ await waitUntil(
577
+ () => isMenuActiveElement(),
578
+ "first item refocused"
579
+ );
580
+ expect(el.open).to.be.true;
581
+ expect(isMenuActiveElement()).to.be.true;
582
+ await sendKeys({ press: "Tab" });
583
+ expect(el.open, "stays open").to.be.true;
593
584
  });
594
585
  describe("tab order", () => {
595
586
  let input1;
@@ -644,7 +635,7 @@ export function runPickerTests() {
644
635
  input1
645
636
  );
646
637
  });
647
- xit('traps tab in the menu as a `type="modal"` overlay forward', async () => {
638
+ it('traps tab in the menu as a `type="modal"` overlay forward', async () => {
648
639
  el.focus();
649
640
  await nextFrame();
650
641
  expect(document.activeElement, "focuses el").to.equal(el);
@@ -653,7 +644,7 @@ export function runPickerTests() {
653
644
  await opened;
654
645
  expect(el.open, "opened").to.be.true;
655
646
  await waitUntil(
656
- () => isMenuActiveElement(el),
647
+ () => isMenuActiveElement(),
657
648
  "first item focused"
658
649
  );
659
650
  const activeElement = document.activeElement;
@@ -666,7 +657,7 @@ export function runPickerTests() {
666
657
  expect(document.activeElement === input2).to.be.false;
667
658
  }
668
659
  });
669
- xit('traps tab in the menu as a `type="modal"` overlay backwards', async () => {
660
+ it('traps tab in the menu as a `type="modal"` overlay backwards', async () => {
670
661
  el.focus();
671
662
  await nextFrame();
672
663
  expect(document.activeElement, "focuses el").to.equal(el);
@@ -675,7 +666,7 @@ export function runPickerTests() {
675
666
  await opened;
676
667
  expect(el.open, "opened").to.be.true;
677
668
  await waitUntil(
678
- () => isMenuActiveElement(el),
669
+ () => isMenuActiveElement(),
679
670
  "first item focused"
680
671
  );
681
672
  const activeElement = document.activeElement;
@@ -688,7 +679,7 @@ export function runPickerTests() {
688
679
  expect(document.activeElement === input2).to.be.false;
689
680
  }
690
681
  });
691
- xit("can close and immediate tab to the next tab stop", async () => {
682
+ it("can close and immediate tab to the next tab stop", async () => {
692
683
  el.focus();
693
684
  await nextFrame();
694
685
  expect(document.activeElement, "focuses el").to.equal(el);
@@ -697,7 +688,7 @@ export function runPickerTests() {
697
688
  await opened;
698
689
  expect(el.open, "opened").to.be.true;
699
690
  await waitUntil(
700
- () => isMenuActiveElement(el),
691
+ () => isMenuActiveElement(),
701
692
  "first item focused"
702
693
  );
703
694
  const closed = oneEvent(el, "sp-closed");
@@ -714,13 +705,13 @@ export function runPickerTests() {
714
705
  it("can close and immediate shift+tab to the previous tab stop", async () => {
715
706
  el.focus();
716
707
  await nextFrame();
717
- expect(document.activeElement === el, "focuses el").to.be.true;
708
+ expect(document.activeElement, "focuses el").to.equal(el);
718
709
  const opened = oneEvent(el, "sp-opened");
719
710
  await sendKeys({ press: "ArrowUp" });
720
711
  await opened;
721
712
  expect(el.open, "opened").to.be.true;
722
713
  await waitUntil(
723
- () => isMenuActiveElement(el),
714
+ () => isMenuActiveElement(),
724
715
  "first item focused"
725
716
  );
726
717
  const closed = oneEvent(el, "sp-closed");
@@ -729,7 +720,7 @@ export function runPickerTests() {
729
720
  expect(el.open).to.be.false;
730
721
  expect(document.activeElement === el).to.be.true;
731
722
  const focused = oneEvent(input1, "focus");
732
- sendKeys({ press: "Shift+Tab" });
723
+ await sendKeys({ press: "Shift+Tab" });
733
724
  await focused;
734
725
  expect(el.open).to.be.false;
735
726
  expect(document.activeElement === input1).to.be.true;
@@ -744,7 +735,8 @@ export function runPickerTests() {
744
735
  expect(el.open).to.be.false;
745
736
  });
746
737
  it("scrolls selected into view on open", async () => {
747
- el.shadowRoot.querySelector("sp-popover").style.height = "40px";
738
+ await el.generatePopover();
739
+ el.popoverEl.style.height = "40px";
748
740
  const firstItem = el.querySelector(
749
741
  "sp-menu-item:first-child"
750
742
  );
@@ -756,12 +748,9 @@ export function runPickerTests() {
756
748
  await elementUpdated(el);
757
749
  el.open = true;
758
750
  await elementUpdated(el);
759
- await waitUntil(
760
- () => isMenuActiveElement(el),
761
- "first item focused"
762
- );
751
+ await waitUntil(() => isMenuActiveElement(), "first item focused");
763
752
  const getParentOffset = (el2) => {
764
- const parentScroll = el2.assignedSlot.parentElement.scrollTop;
753
+ const parentScroll = el2.parentElement.scrollTop;
765
754
  const parentOffset = el2.offsetTop - parentScroll;
766
755
  return parentOffset;
767
756
  };
@@ -808,8 +797,6 @@ export function runPickerTests() {
808
797
  beforeEach(async () => {
809
798
  el = await groupedFixture();
810
799
  await elementUpdated(el);
811
- await nextFrame();
812
- await nextFrame();
813
800
  });
814
801
  it("selects the item with a matching value in a group", async () => {
815
802
  const item = el.querySelector("#should-be-selected");
@@ -968,7 +955,6 @@ export function runPickerTests() {
968
955
  `);
969
956
  const el2 = test.querySelector("sp-picker");
970
957
  await elementUpdated(el2);
971
- await nextFrame();
972
958
  let snapshot = await a11ySnapshot({});
973
959
  expect(
974
960
  findAccessibilityNode(
@@ -979,7 +965,6 @@ export function runPickerTests() {
979
965
  ).to.not.be.null;
980
966
  el2.value = "2";
981
967
  await elementUpdated(el2);
982
- await nextFrame();
983
968
  snapshot = await a11ySnapshot({});
984
969
  expect(
985
970
  findAccessibilityNode(
@@ -1022,7 +1007,7 @@ export function runPickerTests() {
1022
1007
  expect(el1.open).to.be.false;
1023
1008
  });
1024
1009
  it("displays selected item text by default", async () => {
1025
- var _a, _b, _c, _d, _e;
1010
+ var _a, _b, _c, _d;
1026
1011
  const el2 = await fixture(
1027
1012
  html`
1028
1013
  <sp-picker
@@ -1066,13 +1051,9 @@ export function runPickerTests() {
1066
1051
  await opened;
1067
1052
  await elementUpdated(el2.optionsMenu);
1068
1053
  expect(
1069
- el2 === document.activeElement,
1054
+ el2.optionsMenu === document.activeElement,
1070
1055
  `activeElement is ${(_d = document.activeElement) == null ? void 0 : _d.localName}`
1071
1056
  ).to.be.true;
1072
- expect(
1073
- el2.optionsMenu === el2.shadowRoot.activeElement,
1074
- `activeElement is ${(_e = el2.shadowRoot.activeElement) == null ? void 0 : _e.localName}`
1075
- ).to.be.true;
1076
1057
  expect(firstItem.focused, 'firstItem NOT "focused"').to.be.false;
1077
1058
  expect(secondItem.focused, 'secondItem "focused"').to.be.true;
1078
1059
  expect(el2.optionsMenu.getAttribute("aria-activedescendant")).to.equal(
@@ -1159,11 +1140,15 @@ export function runPickerTests() {
1159
1140
  await elementUpdated(el2);
1160
1141
  expect(openedSpy.calledOnce).to.be.true;
1161
1142
  expect(closedSpy.calledOnce).to.be.false;
1143
+ const openedEvent = openedSpy.args[0][0];
1144
+ expect(openedEvent.detail.interaction).to.equal("modal");
1162
1145
  const closed = oneEvent(el2, "sp-closed");
1163
1146
  el2.open = false;
1164
1147
  await closed;
1165
1148
  await elementUpdated(el2);
1166
1149
  expect(closedSpy.calledOnce).to.be.true;
1150
+ const closedEvent = closedSpy.args[0][0];
1151
+ expect(closedEvent.detail.interaction).to.equal("modal");
1167
1152
  });
1168
1153
  }
1169
1154
  //# sourceMappingURL=index.js.map