@spectrum-web-components/picker 0.12.1-devmode.0 → 0.13.0

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
@@ -1,37 +1,4 @@
1
- import {
2
- elementUpdated,
3
- expect,
4
- fixture,
5
- html,
6
- nextFrame,
7
- oneEvent,
8
- waitUntil
9
- } from "@open-wc/testing";
10
- import "@spectrum-web-components/shared/src/focus-visible.js";
11
- import { spy, stub } from "sinon";
12
- import {
13
- arrowDownEvent,
14
- arrowLeftEvent,
15
- arrowRightEvent,
16
- arrowUpEvent,
17
- testForLitDevWarnings,
18
- tEvent
19
- } from "../../../test/testing-helpers.js";
20
- import {
21
- a11ySnapshot,
22
- findAccessibilityNode,
23
- sendKeys
24
- } from "@web/test-runner-commands";
25
- import { iconsOnly } from "../stories/picker.stories.js";
26
- import { sendMouse } from "../../../test/plugins/browser.js";
27
- const isMenuActiveElement = function() {
28
- var _a;
29
- return ((_a = document.activeElement) == null ? void 0 : _a.localName) === "sp-menu";
30
- };
31
- export function runPickerTests() {
32
- let el;
33
- const pickerFixture = async () => {
34
- const test = await fixture(html`
1
+ import{elementUpdated as s,expect as t,fixture as w,html as b,nextFrame as d,oneEvent as i,waitUntil as r}from"@open-wc/testing";import"@spectrum-web-components/shared/src/focus-visible.js";import{spy as h,stub as x}from"sinon";import{arrowDownEvent as M,arrowLeftEvent as T,arrowRightEvent as k,arrowUpEvent as N,testForLitDevWarnings as P,tEvent as C}from"../../../test/testing-helpers.js";import{a11ySnapshot as q,findAccessibilityNode as g,sendKeys as u}from"@web/test-runner-commands";import{iconsOnly as L}from"../stories/picker.stories.js";import{sendMouse as D}from"../../../test/plugins/browser.js";const v=function(){var e;return((e=document.activeElement)==null?void 0:e.localName)==="sp-menu"};export function runPickerTests(){let e;const S=async()=>(await w(b`
35
2
  <div>
36
3
  <sp-field-label for="picker">
37
4
  Where do you live?
@@ -51,636 +18,7 @@ export function runPickerTests() {
51
18
  <sp-menu-item disabled>Make Work Path</sp-menu-item>
52
19
  </sp-picker>
53
20
  </div>
54
- `);
55
- return test.querySelector("sp-picker");
56
- };
57
- describe("standard", () => {
58
- beforeEach(async () => {
59
- el = await pickerFixture();
60
- await elementUpdated(el);
61
- });
62
- afterEach(async () => {
63
- if (el.open) {
64
- const closed = oneEvent(el, "sp-closed");
65
- el.open = false;
66
- await closed;
67
- }
68
- });
69
- it("loads accessibly", async () => {
70
- await expect(el).to.be.accessible();
71
- });
72
- it("closes accessibly", async () => {
73
- const opened = oneEvent(el, "sp-opened");
74
- el.open = true;
75
- await opened;
76
- expect(el.open).to.be.true;
77
- const accessibleCloseButton = document.querySelector(".visually-hidden button");
78
- const closed = oneEvent(el, "sp-closed");
79
- accessibleCloseButton.click();
80
- await closed;
81
- expect(el.open).to.be.false;
82
- });
83
- it("accepts new selected item content", async () => {
84
- const option2 = el.querySelector('[value="option-2"');
85
- el.value = "option-2";
86
- await elementUpdated(option2);
87
- await elementUpdated(el);
88
- expect(el.value).to.equal("option-2");
89
- expect((el.button.textContent || "").trim()).to.equal("Select Inverse");
90
- let itemUpdated = oneEvent(el, "sp-menu-item-added-or-updated");
91
- const newLabel1 = "Invert Selection";
92
- option2.innerHTML = newLabel1;
93
- await itemUpdated;
94
- await elementUpdated(el);
95
- expect(el.value).to.equal("option-2");
96
- expect((el.button.textContent || "").trim()).to.equal(newLabel1);
97
- itemUpdated = oneEvent(el, "sp-menu-item-added-or-updated");
98
- const newLabel2 = "Other option";
99
- option2.childNodes[0].textContent = newLabel2;
100
- await itemUpdated;
101
- await elementUpdated(el);
102
- expect(el.value).to.equal("option-2");
103
- expect((el.button.textContent || "").trim()).to.equal(newLabel2);
104
- });
105
- it("accepts new selected item content when open", async () => {
106
- const option2 = el.querySelector('[value="option-2"');
107
- el.value = "option-2";
108
- await elementUpdated(el);
109
- expect(el.value).to.equal("option-2");
110
- expect((el.button.textContent || "").trim()).to.equal("Select Inverse");
111
- const opened = oneEvent(el, "sp-opened");
112
- el.open = true;
113
- await opened;
114
- const itemUpdated = oneEvent(option2, "sp-menu-item-added-or-updated");
115
- option2.innerHTML = "Invert Selection";
116
- await itemUpdated;
117
- await elementUpdated(el);
118
- expect(el.value).to.equal("option-2");
119
- expect((el.button.textContent || "").trim()).to.equal("Invert Selection");
120
- });
121
- it("unsets value when children removed", async () => {
122
- el.value = "option-2";
123
- await elementUpdated(el);
124
- expect(el.value).to.equal("option-2");
125
- expect((el.button.textContent || "").trim()).to.equal("Select Inverse");
126
- const items = el.querySelectorAll("sp-menu-item");
127
- const removals = [];
128
- items.forEach((item) => {
129
- const removal = oneEvent(el, "sp-menu-item-removed");
130
- item.remove();
131
- removals.push(removal);
132
- });
133
- await Promise.all(removals);
134
- await elementUpdated(el);
135
- expect(el.value).to.equal("");
136
- expect((el.button.textContent || "").trim()).to.equal("");
137
- });
138
- it("accepts a new item and value at the same time", async () => {
139
- el.value = "option-2";
140
- await elementUpdated(el);
141
- expect(el.value).to.equal("option-2");
142
- const item = document.createElement("sp-menu-item");
143
- item.value = "option-new";
144
- item.textContent = "New Option";
145
- el.append(item);
146
- await elementUpdated(el);
147
- el.value = "option-new";
148
- await elementUpdated(el);
149
- expect(el.value).to.equal("option-new");
150
- });
151
- it("accepts a new item that can be selected", async () => {
152
- el.value = "option-2";
153
- await elementUpdated(el);
154
- expect(el.value).to.equal("option-2");
155
- const item = document.createElement("sp-menu-item");
156
- item.value = "option-new";
157
- item.textContent = "New Option";
158
- el.append(item);
159
- await elementUpdated(item);
160
- await elementUpdated(el);
161
- let opened = oneEvent(el, "sp-opened");
162
- el.open = true;
163
- await opened;
164
- await nextFrame();
165
- const close = oneEvent(el, "sp-closed");
166
- item.click();
167
- await close;
168
- await nextFrame();
169
- expect(el.value, "first time").to.equal("option-new");
170
- opened = oneEvent(el, "sp-opened");
171
- el.open = true;
172
- await opened;
173
- await nextFrame();
174
- expect(el.value, "second time").to.equal("option-new");
175
- });
176
- it('manages its "name" value in the accessibility tree', async () => {
177
- let snapshot = await a11ySnapshot({});
178
- expect(findAccessibilityNode(snapshot, (node) => node.name === "Where do you live?"), "`name` is the label text").to.not.be.null;
179
- el.value = "option-2";
180
- await elementUpdated(el);
181
- snapshot = await a11ySnapshot({});
182
- expect(findAccessibilityNode(snapshot, (node) => node.name === "Where do you live? Select Inverse"), "`name` is the label text plus the selected item text").to.not.be.null;
183
- });
184
- it("manages `aria-activedescendant`", async () => {
185
- const firstItem = el.querySelector("sp-menu-item:nth-child(1)");
186
- const secondItem = el.querySelector("sp-menu-item:nth-child(2)");
187
- const opened = oneEvent(el, "sp-opened");
188
- el.open = true;
189
- await opened;
190
- expect(el.optionsMenu.getAttribute("aria-activedescendant")).to.equal(firstItem == null ? void 0 : firstItem.id);
191
- await sendKeys({ press: "ArrowDown" });
192
- await elementUpdated(el);
193
- expect(el.optionsMenu.getAttribute("aria-activedescendant")).to.equal(secondItem == null ? void 0 : secondItem.id);
194
- });
195
- it("renders invalid accessibly", async () => {
196
- el.invalid = true;
197
- await elementUpdated(el);
198
- expect(el.invalid).to.be.true;
199
- await expect(el).to.be.accessible();
200
- });
201
- it("renders selection accessibly", async () => {
202
- el.value = "option-2";
203
- await elementUpdated(el);
204
- await expect(el).to.be.accessible();
205
- });
206
- it("opens with visible focus on a menu item on `DownArrow`", async () => {
207
- const firstItem = el.querySelector("sp-menu-item");
208
- await elementUpdated(el);
209
- expect(firstItem.focused, "should not visually focused").to.be.false;
210
- el.focus();
211
- await elementUpdated(el);
212
- const opened = oneEvent(el, "sp-opened");
213
- await sendKeys({ press: "ArrowRight" });
214
- await sendKeys({ press: "ArrowLeft" });
215
- await sendKeys({ press: "ArrowDown" });
216
- await opened;
217
- expect(el.open).to.be.true;
218
- expect(firstItem.focused, "should be visually focused").to.be.true;
219
- const closed = oneEvent(el, "sp-closed");
220
- await sendKeys({
221
- press: "Escape"
222
- });
223
- await closed;
224
- expect(el.open).to.be.false;
225
- await waitUntil(() => !firstItem.focused, "not visually focused");
226
- });
227
- it("opens without visible focus on a menu item on click", async () => {
228
- const firstItem = el.querySelector("sp-menu-item");
229
- await elementUpdated(el);
230
- const boundingRect = el.getBoundingClientRect();
231
- expect(firstItem.focused, "not visually focused").to.be.false;
232
- const opened = oneEvent(el, "sp-opened");
233
- sendMouse({
234
- steps: [
235
- {
236
- type: "click",
237
- position: [
238
- boundingRect.x + boundingRect.width / 2,
239
- boundingRect.y + boundingRect.height / 2
240
- ]
241
- }
242
- ]
243
- });
244
- await opened;
245
- await elementUpdated(el);
246
- expect(el.open).to.be.true;
247
- expect(firstItem.focused, "still not visually focused").to.be.false;
248
- });
249
- it("closes when becoming disabled", async () => {
250
- expect(el.open).to.be.false;
251
- el.click();
252
- await elementUpdated(el);
253
- expect(el.open).to.be.true;
254
- el.disabled = true;
255
- await elementUpdated(el);
256
- expect(el.open).to.be.false;
257
- });
258
- it("closes when clicking away", async () => {
259
- el.id = "closing";
260
- const other = document.createElement("div");
261
- document.body.append(other);
262
- await elementUpdated(el);
263
- expect(el.open).to.be.false;
264
- el.click();
265
- await elementUpdated(el);
266
- expect(el.open).to.be.true;
267
- other.click();
268
- await waitUntil(() => !el.open, "closed");
269
- other.remove();
270
- });
271
- it("selects", async () => {
272
- var _a, _b;
273
- const secondItem = el.querySelector("sp-menu-item:nth-of-type(2)");
274
- const button = el.button;
275
- const opened = oneEvent(el, "sp-opened");
276
- button.click();
277
- await opened;
278
- await elementUpdated(el);
279
- expect(el.open).to.be.true;
280
- expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
281
- expect(el.value).to.equal("");
282
- const closed = oneEvent(el, "sp-closed");
283
- secondItem.click();
284
- await closed;
285
- expect(el.open).to.be.false;
286
- expect((_b = el.selectedItem) == null ? void 0 : _b.itemText).to.equal("Select Inverse");
287
- expect(el.value).to.equal("option-2");
288
- });
289
- it("re-selects", async () => {
290
- var _a, _b, _c, _d;
291
- const firstItem = el.querySelector("sp-menu-item:nth-of-type(1)");
292
- const secondItem = el.querySelector("sp-menu-item:nth-of-type(2)");
293
- const button = el.button;
294
- const opened = oneEvent(el, "sp-opened");
295
- button.click();
296
- await opened;
297
- await nextFrame();
298
- expect(el.open).to.be.true;
299
- expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
300
- expect(el.value).to.equal("");
301
- const closed = oneEvent(el, "sp-closed");
302
- secondItem.click();
303
- await closed;
304
- await nextFrame();
305
- expect(el.open).to.be.false;
306
- expect((_b = el.selectedItem) == null ? void 0 : _b.itemText).to.equal("Select Inverse");
307
- expect(el.value).to.equal("option-2");
308
- const opened2 = oneEvent(el, "sp-opened");
309
- button.click();
310
- await opened2;
311
- await nextFrame();
312
- expect(el.open).to.be.true;
313
- expect((_c = el.selectedItem) == null ? void 0 : _c.itemText).to.equal("Select Inverse");
314
- expect(el.value).to.equal("option-2");
315
- const closed2 = oneEvent(el, "sp-closed");
316
- firstItem.click();
317
- await closed2;
318
- await nextFrame();
319
- expect(el.open).to.be.false;
320
- expect((_d = el.selectedItem) == null ? void 0 : _d.itemText).to.equal("Deselect");
321
- expect(el.value).to.equal("Deselect");
322
- });
323
- it("dispatches bubbling and composed events", async () => {
324
- const changeSpy = spy();
325
- const parent = el.parentElement;
326
- parent.attachShadow({ mode: "open" });
327
- parent.shadowRoot.append(el);
328
- const secondItem = el.querySelector("sp-menu-item:nth-of-type(2)");
329
- parent.addEventListener("change", () => changeSpy());
330
- expect(el.value).to.equal("");
331
- const opened = oneEvent(el, "sp-opened");
332
- el.open = true;
333
- await opened;
334
- await elementUpdated(el);
335
- const closed = oneEvent(el, "sp-closed");
336
- secondItem.click();
337
- await closed;
338
- await elementUpdated(el);
339
- expect(el.value).to.equal(secondItem.value);
340
- expect(changeSpy.calledOnce).to.be.true;
341
- });
342
- it("can have selection prevented", async () => {
343
- var _a;
344
- const preventChangeSpy = spy();
345
- const secondItem = el.querySelector("sp-menu-item:nth-of-type(2)");
346
- const button = el.button;
347
- let opened = oneEvent(el, "sp-opened");
348
- button.click();
349
- await opened;
350
- await elementUpdated(el);
351
- expect(el.open).to.be.true;
352
- expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
353
- expect(el.value).to.equal("");
354
- expect(secondItem.selected).to.be.false;
355
- el.addEventListener("change", (event) => {
356
- event.preventDefault();
357
- preventChangeSpy();
358
- });
359
- const closed = oneEvent(el, "sp-closed");
360
- opened = oneEvent(el, "sp-opened");
361
- secondItem.click();
362
- await closed;
363
- await opened;
364
- await elementUpdated(el);
365
- expect(preventChangeSpy.calledOnce).to.be.true;
366
- expect(secondItem.selected, "selection prevented").to.be.false;
367
- });
368
- it("can throw focus after `change`", async () => {
369
- var _a;
370
- const input = document.createElement("input");
371
- document.body.append(input);
372
- await elementUpdated(el);
373
- const secondItem = el.querySelector("sp-menu-item:nth-of-type(2)");
374
- const button = el.button;
375
- const opened = oneEvent(el, "sp-opened");
376
- button.click();
377
- await opened;
378
- await elementUpdated(el);
379
- expect(el.open).to.be.true;
380
- expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
381
- expect(el.value).to.equal("");
382
- expect(secondItem.selected).to.be.false;
383
- el.addEventListener("change", () => {
384
- input.focus();
385
- });
386
- const closed = oneEvent(el, "sp-closed");
387
- secondItem.click();
388
- await closed;
389
- await elementUpdated(el);
390
- expect(el.open).to.be.false;
391
- expect(el.value, "value changed").to.equal("option-2");
392
- expect(secondItem.selected, "selected changed").to.be.true;
393
- await waitUntil(() => document.activeElement === input, "focus throw");
394
- input.remove();
395
- });
396
- it("opens on ArrowUp", async () => {
397
- const button = el.button;
398
- el.focus();
399
- await elementUpdated(el);
400
- expect(el.open, "inially closed").to.be.false;
401
- button.dispatchEvent(tEvent());
402
- await elementUpdated(el);
403
- expect(el.open, "still closed").to.be.false;
404
- button.dispatchEvent(arrowUpEvent());
405
- await elementUpdated(el);
406
- expect(el.open, "open by ArrowUp").to.be.true;
407
- await waitUntil(() => document.querySelector("active-overlay") !== null, "an active-overlay has been inserted on the page");
408
- button.dispatchEvent(new KeyboardEvent("keyup", {
409
- bubbles: true,
410
- composed: true,
411
- cancelable: true,
412
- key: "Escape",
413
- code: "Escape"
414
- }));
415
- await elementUpdated(el);
416
- await waitUntil(() => el.open === false, "closed by Escape");
417
- await waitUntil(() => document.querySelector("active-overlay") === null, "an active-overlay has been inserted on the page");
418
- });
419
- it("opens on ArrowDown", async () => {
420
- var _a, _b;
421
- const firstItem = el.querySelector("sp-menu-item:nth-of-type(1)");
422
- const button = el.button;
423
- el.focus();
424
- await elementUpdated(el);
425
- expect(el.open, "inially closed").to.be.false;
426
- const opened = oneEvent(el, "sp-opened");
427
- button.dispatchEvent(arrowDownEvent());
428
- await opened;
429
- await elementUpdated(el);
430
- expect(el.open, "open by ArrowDown").to.be.true;
431
- expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
432
- expect(el.value).to.equal("");
433
- const closed = oneEvent(el, "sp-closed");
434
- firstItem.click();
435
- await closed;
436
- await elementUpdated(el);
437
- expect(el.open).to.be.false;
438
- expect((_b = el.selectedItem) == null ? void 0 : _b.itemText).to.equal("Deselect");
439
- expect(el.value).to.equal("Deselect");
440
- });
441
- it("quick selects on ArrowLeft/Right", async () => {
442
- const selectionSpy = spy();
443
- el.addEventListener("change", (event) => {
444
- const { value } = event.target;
445
- selectionSpy(value);
446
- });
447
- const button = el.button;
448
- el.focus();
449
- button.dispatchEvent(arrowLeftEvent());
450
- await elementUpdated(el);
451
- expect(selectionSpy.callCount).to.equal(1);
452
- expect(selectionSpy.calledWith("Deselected"));
453
- button.dispatchEvent(arrowLeftEvent());
454
- await elementUpdated(el);
455
- expect(selectionSpy.callCount).to.equal(1);
456
- button.dispatchEvent(arrowRightEvent());
457
- await elementUpdated(el);
458
- expect(selectionSpy.calledWith("option-2"));
459
- button.dispatchEvent(arrowRightEvent());
460
- button.dispatchEvent(arrowRightEvent());
461
- button.dispatchEvent(arrowRightEvent());
462
- button.dispatchEvent(arrowRightEvent());
463
- await elementUpdated(el);
464
- expect(selectionSpy.callCount).to.equal(5);
465
- expect(selectionSpy.calledWith("Save Selection"));
466
- expect(selectionSpy.calledWith("Make Work Path")).to.be.false;
467
- });
468
- it("quick selects first item on ArrowRight when no value", async () => {
469
- const selectionSpy = spy();
470
- el.addEventListener("change", (event) => {
471
- const { value } = event.target;
472
- selectionSpy(value);
473
- });
474
- const button = el.button;
475
- el.focus();
476
- button.dispatchEvent(arrowRightEvent());
477
- await elementUpdated(el);
478
- expect(selectionSpy.callCount).to.equal(1);
479
- expect(selectionSpy.calledWith("Deselected"));
480
- });
481
- it("loads", async () => {
482
- expect(el).to.not.be.undefined;
483
- });
484
- it("refocuses on list when open", async () => {
485
- const firstItem = el.querySelector("sp-menu-item");
486
- const input = document.createElement("input");
487
- el.insertAdjacentElement("afterend", input);
488
- el.focus();
489
- await sendKeys({ press: "Tab" });
490
- expect(document.activeElement === input).to.be.true;
491
- await sendKeys({ press: "Shift+Tab" });
492
- expect(document.activeElement === el).to.be.true;
493
- await sendKeys({ press: "Enter" });
494
- const opened = oneEvent(el, "sp-opened");
495
- el.open = true;
496
- await opened;
497
- await elementUpdated(el);
498
- await waitUntil(() => firstItem.focused, "The first items should have become focused visually.");
499
- el.blur();
500
- await elementUpdated(el);
501
- expect(el.open).to.be.true;
502
- el.focus();
503
- await elementUpdated(el);
504
- await waitUntil(() => isMenuActiveElement(), "first item refocused");
505
- expect(el.open).to.be.true;
506
- expect(isMenuActiveElement()).to.be.true;
507
- await sendKeys({ press: "ArrowDown" });
508
- await sendKeys({ press: "ArrowUp" });
509
- expect(firstItem.focused).to.be.true;
510
- });
511
- it("does not allow tabing to close", async () => {
512
- el.open = true;
513
- await elementUpdated(el);
514
- expect(el.open).to.be.true;
515
- el.focus();
516
- await elementUpdated(el);
517
- await waitUntil(() => isMenuActiveElement(), "first item refocused");
518
- expect(el.open).to.be.true;
519
- expect(isMenuActiveElement()).to.be.true;
520
- await sendKeys({ press: "Tab" });
521
- expect(el.open, "stays open").to.be.true;
522
- });
523
- describe("tab order", () => {
524
- let input1;
525
- let input2;
526
- beforeEach(() => {
527
- const surroundingInput = () => {
528
- const input = document.createElement("input");
529
- input.type = "text";
530
- input.tabIndex = 0;
531
- return input;
532
- };
533
- input1 = surroundingInput();
534
- input2 = surroundingInput();
535
- el.insertAdjacentElement("beforebegin", input1);
536
- el.insertAdjacentElement("afterend", input2);
537
- });
538
- afterEach(() => {
539
- input1.remove();
540
- input2.remove();
541
- });
542
- it("tabs forward through the element", async () => {
543
- input1.focus();
544
- await nextFrame();
545
- expect(document.activeElement === input1, "focuses input 1").to.true;
546
- let focused = oneEvent(el, "focus");
547
- await sendKeys({ press: "Tab" });
548
- await focused;
549
- expect(el.focused, "focused").to.be.true;
550
- expect(el.open, "closed").to.be.false;
551
- expect(document.activeElement === el, "focuses el").to.be.true;
552
- focused = oneEvent(input2, "focus");
553
- await sendKeys({ press: "Tab" });
554
- await focused;
555
- expect(document.activeElement === input2, "focuses input 2").to.true;
556
- });
557
- it("shift+tabs backwards through the element", async () => {
558
- input2.focus();
559
- await nextFrame();
560
- expect(document.activeElement, "focuses input 2").to.equal(input2);
561
- let focused = oneEvent(el, "focus");
562
- await sendKeys({ press: "Shift+Tab" });
563
- await focused;
564
- expect(el.focused, "focused").to.be.true;
565
- expect(el.open, "closed").to.be.false;
566
- expect(document.activeElement, "focuses el").to.equal(el);
567
- focused = oneEvent(input1, "focus");
568
- await sendKeys({ press: "Shift+Tab" });
569
- await focused;
570
- expect(document.activeElement, "focuses input 1").to.equal(input1);
571
- });
572
- it('traps tab in the menu as a `type="modal"` overlay forward', async () => {
573
- el.focus();
574
- await nextFrame();
575
- expect(document.activeElement, "focuses el").to.equal(el);
576
- const opened = oneEvent(el, "sp-opened");
577
- await sendKeys({ press: "ArrowDown" });
578
- await opened;
579
- expect(el.open, "opened").to.be.true;
580
- await waitUntil(() => isMenuActiveElement(), "first item focused");
581
- const activeElement = document.activeElement;
582
- const blured = oneEvent(activeElement, "blur");
583
- await sendKeys({ press: "Tab" });
584
- await blured;
585
- expect(el.open).to.be.true;
586
- expect(document.activeElement === input1).to.be.false;
587
- expect(document.activeElement === input2).to.be.false;
588
- });
589
- it('traps tab in the menu as a `type="modal"` overlay backwards', async () => {
590
- el.focus();
591
- await nextFrame();
592
- expect(document.activeElement, "focuses el").to.equal(el);
593
- const opened = oneEvent(el, "sp-opened");
594
- await sendKeys({ press: "ArrowDown" });
595
- await opened;
596
- expect(el.open, "opened").to.be.true;
597
- await waitUntil(() => isMenuActiveElement(), "first item focused");
598
- const activeElement = document.activeElement;
599
- const blured = oneEvent(activeElement, "blur");
600
- await sendKeys({ press: "Shift+Tab" });
601
- await blured;
602
- expect(el.open).to.be.true;
603
- expect(document.activeElement === input1).to.be.false;
604
- expect(document.activeElement === input2).to.be.false;
605
- });
606
- it("can close and immediate tab to the next tab stop", async () => {
607
- el.focus();
608
- await nextFrame();
609
- expect(document.activeElement, "focuses el").to.equal(el);
610
- const opened = oneEvent(el, "sp-opened");
611
- await sendKeys({ press: "ArrowUp" });
612
- await opened;
613
- expect(el.open, "opened").to.be.true;
614
- await waitUntil(() => isMenuActiveElement(), "first item focused");
615
- const closed = oneEvent(el, "sp-closed");
616
- el.open = false;
617
- await closed;
618
- expect(el.open).to.be.false;
619
- expect(document.activeElement === el).to.be.true;
620
- const focused = oneEvent(input2, "focus");
621
- await sendKeys({ press: "Tab" });
622
- await focused;
623
- expect(el.open).to.be.false;
624
- expect(document.activeElement === input2).to.be.true;
625
- });
626
- it("can close and immediate shift+tab to the previous tab stop", async () => {
627
- el.focus();
628
- await nextFrame();
629
- expect(document.activeElement, "focuses el").to.equal(el);
630
- const opened = oneEvent(el, "sp-opened");
631
- await sendKeys({ press: "ArrowUp" });
632
- await opened;
633
- expect(el.open, "opened").to.be.true;
634
- await waitUntil(() => isMenuActiveElement(), "first item focused");
635
- const closed = oneEvent(el, "sp-closed");
636
- el.open = false;
637
- await closed;
638
- expect(el.open).to.be.false;
639
- expect(document.activeElement === el).to.be.true;
640
- const focused = oneEvent(input1, "focus");
641
- await sendKeys({ press: "Shift+Tab" });
642
- await focused;
643
- expect(el.open).to.be.false;
644
- expect(document.activeElement === input1).to.be.true;
645
- });
646
- });
647
- it("does not open when [readonly]", async () => {
648
- el.readonly = true;
649
- await elementUpdated(el);
650
- const button = el.button;
651
- button.click();
652
- await elementUpdated(el);
653
- expect(el.open).to.be.false;
654
- });
655
- it("scrolls selected into view on open", async () => {
656
- await el.generatePopover();
657
- el.popover.style.height = "40px";
658
- const firstItem = el.querySelector("sp-menu-item:first-child");
659
- const lastItem = el.querySelector("sp-menu-item:last-child");
660
- lastItem.disabled = false;
661
- el.value = lastItem.value;
662
- await elementUpdated(el);
663
- el.open = true;
664
- await elementUpdated(el);
665
- await waitUntil(() => isMenuActiveElement(), "first item focused");
666
- const getParentOffset = (el2) => {
667
- const parentScroll = el2.parentElement.scrollTop;
668
- const parentOffset = el2.offsetTop - parentScroll;
669
- return parentOffset;
670
- };
671
- expect(getParentOffset(lastItem)).to.be.lessThan(40);
672
- expect(getParentOffset(firstItem)).to.be.lessThan(-1);
673
- lastItem.dispatchEvent(new FocusEvent("focusin", { bubbles: true }));
674
- lastItem.dispatchEvent(arrowDownEvent());
675
- await elementUpdated(el);
676
- await nextFrame();
677
- expect(getParentOffset(lastItem)).to.be.greaterThan(40);
678
- expect(getParentOffset(firstItem)).to.be.greaterThan(-1);
679
- });
680
- });
681
- describe("grouped", async () => {
682
- const groupedFixture = async () => {
683
- return fixture(html`
21
+ `)).querySelector("sp-picker");describe("standard",()=>{beforeEach(async()=>{e=await S(),await s(e)}),afterEach(async()=>{if(e.open){const a=i(e,"sp-closed");e.open=!1,await a}}),it("loads accessibly",async()=>{await t(e).to.be.accessible()}),it("closes accessibly",async()=>{const a=i(e,"sp-opened");e.open=!0,await a,t(e.open).to.be.true;const o=document.querySelector(".visually-hidden button"),n=i(e,"sp-closed");o.click(),await n,t(e.open).to.be.false}),it("accepts new selected item content",async()=>{const a=e.querySelector('[value="option-2"');e.value="option-2",await s(a),await s(e),t(e.value).to.equal("option-2"),t((e.button.textContent||"").trim()).to.equal("Select Inverse");let o=i(e,"sp-menu-item-added-or-updated");const n="Invert Selection";a.innerHTML=n,await o,await s(e),t(e.value).to.equal("option-2"),t((e.button.textContent||"").trim()).to.equal(n),o=i(e,"sp-menu-item-added-or-updated");const c="Other option";a.childNodes[0].textContent=c,await o,await s(e),t(e.value).to.equal("option-2"),t((e.button.textContent||"").trim()).to.equal(c)}),it("accepts new selected item content when open",async()=>{const a=e.querySelector('[value="option-2"');e.value="option-2",await s(e),t(e.value).to.equal("option-2"),t((e.button.textContent||"").trim()).to.equal("Select Inverse");const o=i(e,"sp-opened");e.open=!0,await o;const n=i(a,"sp-menu-item-added-or-updated");a.innerHTML="Invert Selection",await n,await s(e),t(e.value).to.equal("option-2"),t((e.button.textContent||"").trim()).to.equal("Invert Selection")}),it("unsets value when children removed",async()=>{e.value="option-2",await s(e),t(e.value).to.equal("option-2"),t((e.button.textContent||"").trim()).to.equal("Select Inverse");const a=e.querySelectorAll("sp-menu-item"),o=[];a.forEach(n=>{const c=i(e,"sp-menu-item-removed");n.remove(),o.push(c)}),await Promise.all(o),await s(e),t(e.value).to.equal(""),t((e.button.textContent||"").trim()).to.equal("")}),it("accepts a new item and value at the same time",async()=>{e.value="option-2",await s(e),t(e.value).to.equal("option-2");const a=document.createElement("sp-menu-item");a.value="option-new",a.textContent="New Option",e.append(a),await s(e),e.value="option-new",await s(e),t(e.value).to.equal("option-new")}),it("accepts a new item that can be selected",async()=>{e.value="option-2",await s(e),t(e.value).to.equal("option-2");const a=document.createElement("sp-menu-item");a.value="option-new",a.textContent="New Option",e.append(a),await s(a),await s(e);let o=i(e,"sp-opened");e.open=!0,await o,await d();const n=i(e,"sp-closed");a.click(),await n,await d(),t(e.value,"first time").to.equal("option-new"),o=i(e,"sp-opened"),e.open=!0,await o,await d(),t(e.value,"second time").to.equal("option-new")}),it('manages its "name" value in the accessibility tree',async()=>{let a=await q({});t(g(a,o=>o.name==="Where do you live?"),"`name` is the label text").to.not.be.null,e.value="option-2",await s(e),a=await q({}),t(g(a,o=>o.name==="Where do you live? Select Inverse"),"`name` is the label text plus the selected item text").to.not.be.null}),it("manages `aria-activedescendant`",async()=>{const a=e.querySelector("sp-menu-item:nth-child(1)"),o=e.querySelector("sp-menu-item:nth-child(2)"),n=i(e,"sp-opened");e.open=!0,await n,t(e.optionsMenu.getAttribute("aria-activedescendant")).to.equal(a==null?void 0:a.id),await u({press:"ArrowDown"}),await s(e),t(e.optionsMenu.getAttribute("aria-activedescendant")).to.equal(o==null?void 0:o.id)}),it("renders invalid accessibly",async()=>{e.invalid=!0,await s(e),t(e.invalid).to.be.true,await t(e).to.be.accessible()}),it("renders selection accessibly",async()=>{e.value="option-2",await s(e),await t(e).to.be.accessible()}),it("opens with visible focus on a menu item on `DownArrow`",async()=>{const a=e.querySelector("sp-menu-item");await s(e),t(a.focused,"should not visually focused").to.be.false,e.focus(),await s(e);const o=i(e,"sp-opened");await u({press:"ArrowRight"}),await u({press:"ArrowLeft"}),await u({press:"ArrowDown"}),await o,t(e.open).to.be.true,t(a.focused,"should be visually focused").to.be.true;const n=i(e,"sp-closed");await u({press:"Escape"}),await n,t(e.open).to.be.false,await r(()=>!a.focused,"not visually focused")}),it("opens without visible focus on a menu item on click",async()=>{const a=e.querySelector("sp-menu-item");await s(e);const o=e.getBoundingClientRect();t(a.focused,"not visually focused").to.be.false;const n=i(e,"sp-opened");D({steps:[{type:"click",position:[o.x+o.width/2,o.y+o.height/2]}]}),await n,await s(e),t(e.open).to.be.true,t(a.focused,"still not visually focused").to.be.false}),it("closes when becoming disabled",async()=>{t(e.open).to.be.false,e.click(),await s(e),t(e.open).to.be.true,e.disabled=!0,await s(e),t(e.open).to.be.false}),it("closes when clicking away",async()=>{e.id="closing";const a=document.createElement("div");document.body.append(a),await s(e),t(e.open).to.be.false,e.click(),await s(e),t(e.open).to.be.true,a.click(),await r(()=>!e.open,"closed"),a.remove()}),it("selects",async()=>{var l,p;const a=e.querySelector("sp-menu-item:nth-of-type(2)"),o=e.button,n=i(e,"sp-opened");o.click(),await n,await s(e),t(e.open).to.be.true,t((l=e.selectedItem)==null?void 0:l.itemText).to.be.undefined,t(e.value).to.equal("");const c=i(e,"sp-closed");a.click(),await c,t(e.open).to.be.false,t((p=e.selectedItem)==null?void 0:p.itemText).to.equal("Select Inverse"),t(e.value).to.equal("option-2")}),it("re-selects",async()=>{var f,y,E,I;const a=e.querySelector("sp-menu-item:nth-of-type(1)"),o=e.querySelector("sp-menu-item:nth-of-type(2)"),n=e.button,c=i(e,"sp-opened");n.click(),await c,await d(),t(e.open).to.be.true,t((f=e.selectedItem)==null?void 0:f.itemText).to.be.undefined,t(e.value).to.equal("");const l=i(e,"sp-closed");o.click(),await l,await d(),t(e.open).to.be.false,t((y=e.selectedItem)==null?void 0:y.itemText).to.equal("Select Inverse"),t(e.value).to.equal("option-2");const p=i(e,"sp-opened");n.click(),await p,await d(),t(e.open).to.be.true,t((E=e.selectedItem)==null?void 0:E.itemText).to.equal("Select Inverse"),t(e.value).to.equal("option-2");const m=i(e,"sp-closed");a.click(),await m,await d(),t(e.open).to.be.false,t((I=e.selectedItem)==null?void 0:I.itemText).to.equal("Deselect"),t(e.value).to.equal("Deselect")}),it("dispatches bubbling and composed events",async()=>{const a=h(),o=e.parentElement;o.attachShadow({mode:"open"}),o.shadowRoot.append(e);const n=e.querySelector("sp-menu-item:nth-of-type(2)");o.addEventListener("change",()=>a()),t(e.value).to.equal("");const c=i(e,"sp-opened");e.open=!0,await c,await s(e);const l=i(e,"sp-closed");n.click(),await l,await s(e),t(e.value).to.equal(n.value),t(a.calledOnce).to.be.true}),it("can have selection prevented",async()=>{var p;const a=h(),o=e.querySelector("sp-menu-item:nth-of-type(2)"),n=e.button;let c=i(e,"sp-opened");n.click(),await c,await s(e),t(e.open).to.be.true,t((p=e.selectedItem)==null?void 0:p.itemText).to.be.undefined,t(e.value).to.equal(""),t(o.selected).to.be.false,e.addEventListener("change",m=>{m.preventDefault(),a()});const l=i(e,"sp-closed");c=i(e,"sp-opened"),o.click(),await l,await c,await s(e),t(a.calledOnce).to.be.true,t(o.selected,"selection prevented").to.be.false}),it("can throw focus after `change`",async()=>{var p;const a=document.createElement("input");document.body.append(a),await s(e);const o=e.querySelector("sp-menu-item:nth-of-type(2)"),n=e.button,c=i(e,"sp-opened");n.click(),await c,await s(e),t(e.open).to.be.true,t((p=e.selectedItem)==null?void 0:p.itemText).to.be.undefined,t(e.value).to.equal(""),t(o.selected).to.be.false,e.addEventListener("change",()=>{a.focus()});const l=i(e,"sp-closed");o.click(),await l,await s(e),t(e.open).to.be.false,t(e.value,"value changed").to.equal("option-2"),t(o.selected,"selected changed").to.be.true,await r(()=>document.activeElement===a,"focus throw"),a.remove()}),it("opens on ArrowUp",async()=>{const a=e.button;e.focus(),await s(e),t(e.open,"inially closed").to.be.false,a.dispatchEvent(C()),await s(e),t(e.open,"still closed").to.be.false,a.dispatchEvent(N()),await s(e),t(e.open,"open by ArrowUp").to.be.true,await r(()=>document.querySelector("active-overlay")!==null,"an active-overlay has been inserted on the page"),a.dispatchEvent(new KeyboardEvent("keyup",{bubbles:!0,composed:!0,cancelable:!0,key:"Escape",code:"Escape"})),await s(e),await r(()=>e.open===!1,"closed by Escape"),await r(()=>document.querySelector("active-overlay")===null,"an active-overlay has been inserted on the page")}),it("opens on ArrowDown",async()=>{var l,p;const a=e.querySelector("sp-menu-item:nth-of-type(1)"),o=e.button;e.focus(),await s(e),t(e.open,"inially closed").to.be.false;const n=i(e,"sp-opened");o.dispatchEvent(M()),await n,await s(e),t(e.open,"open by ArrowDown").to.be.true,t((l=e.selectedItem)==null?void 0:l.itemText).to.be.undefined,t(e.value).to.equal("");const c=i(e,"sp-closed");a.click(),await c,await s(e),t(e.open).to.be.false,t((p=e.selectedItem)==null?void 0:p.itemText).to.equal("Deselect"),t(e.value).to.equal("Deselect")}),it("quick selects on ArrowLeft/Right",async()=>{const a=h();e.addEventListener("change",n=>{const{value:c}=n.target;a(c)});const o=e.button;e.focus(),o.dispatchEvent(T()),await s(e),t(a.callCount).to.equal(1),t(a.calledWith("Deselected")),o.dispatchEvent(T()),await s(e),t(a.callCount).to.equal(1),o.dispatchEvent(k()),await s(e),t(a.calledWith("option-2")),o.dispatchEvent(k()),o.dispatchEvent(k()),o.dispatchEvent(k()),o.dispatchEvent(k()),await s(e),t(a.callCount).to.equal(5),t(a.calledWith("Save Selection")),t(a.calledWith("Make Work Path")).to.be.false}),it("quick selects first item on ArrowRight when no value",async()=>{const a=h();e.addEventListener("change",n=>{const{value:c}=n.target;a(c)});const o=e.button;e.focus(),o.dispatchEvent(k()),await s(e),t(a.callCount).to.equal(1),t(a.calledWith("Deselected"))}),it("loads",async()=>{t(e).to.not.be.undefined}),it("refocuses on list when open",async()=>{const a=e.querySelector("sp-menu-item"),o=document.createElement("input");e.insertAdjacentElement("afterend",o),e.focus(),await u({press:"Tab"}),t(document.activeElement===o).to.be.true,await u({press:"Shift+Tab"}),t(document.activeElement===e).to.be.true,await u({press:"Enter"});const n=i(e,"sp-opened");e.open=!0,await n,await s(e),await r(()=>a.focused,"The first items should have become focused visually."),e.blur(),await s(e),t(e.open).to.be.true,e.focus(),await s(e),await r(()=>v(),"first item refocused"),t(e.open).to.be.true,t(v()).to.be.true,await u({press:"ArrowDown"}),await u({press:"ArrowUp"}),t(a.focused).to.be.true}),it("does not allow tabing to close",async()=>{e.open=!0,await s(e),t(e.open).to.be.true,e.focus(),await s(e),await r(()=>v(),"first item refocused"),t(e.open).to.be.true,t(v()).to.be.true,await u({press:"Tab"}),t(e.open,"stays open").to.be.true}),describe("tab order",()=>{let a,o;beforeEach(()=>{const n=()=>{const c=document.createElement("input");return c.type="text",c.tabIndex=0,c};a=n(),o=n(),e.insertAdjacentElement("beforebegin",a),e.insertAdjacentElement("afterend",o)}),afterEach(()=>{a.remove(),o.remove()}),it("tabs forward through the element",async()=>{a.focus(),await d(),t(document.activeElement===a,"focuses input 1").to.true;let n=i(e,"focus");await u({press:"Tab"}),await n,t(e.focused,"focused").to.be.true,t(e.open,"closed").to.be.false,t(document.activeElement===e,"focuses el").to.be.true,n=i(o,"focus"),await u({press:"Tab"}),await n,t(document.activeElement===o,"focuses input 2").to.true}),it("shift+tabs backwards through the element",async()=>{o.focus(),await d(),t(document.activeElement,"focuses input 2").to.equal(o);let n=i(e,"focus");await u({press:"Shift+Tab"}),await n,t(e.focused,"focused").to.be.true,t(e.open,"closed").to.be.false,t(document.activeElement,"focuses el").to.equal(e),n=i(a,"focus"),await u({press:"Shift+Tab"}),await n,t(document.activeElement,"focuses input 1").to.equal(a)}),it('traps tab in the menu as a `type="modal"` overlay forward',async()=>{e.focus(),await d(),t(document.activeElement,"focuses el").to.equal(e);const n=i(e,"sp-opened");await u({press:"ArrowDown"}),await n,t(e.open,"opened").to.be.true,await r(()=>v(),"first item focused");const c=document.activeElement,l=i(c,"blur");await u({press:"Tab"}),await l,t(e.open).to.be.true,t(document.activeElement===a).to.be.false,t(document.activeElement===o).to.be.false}),it('traps tab in the menu as a `type="modal"` overlay backwards',async()=>{e.focus(),await d(),t(document.activeElement,"focuses el").to.equal(e);const n=i(e,"sp-opened");await u({press:"ArrowDown"}),await n,t(e.open,"opened").to.be.true,await r(()=>v(),"first item focused");const c=document.activeElement,l=i(c,"blur");await u({press:"Shift+Tab"}),await l,t(e.open).to.be.true,t(document.activeElement===a).to.be.false,t(document.activeElement===o).to.be.false}),it("can close and immediate tab to the next tab stop",async()=>{e.focus(),await d(),t(document.activeElement,"focuses el").to.equal(e);const n=i(e,"sp-opened");await u({press:"ArrowUp"}),await n,t(e.open,"opened").to.be.true,await r(()=>v(),"first item focused");const c=i(e,"sp-closed");e.open=!1,await c,t(e.open).to.be.false,t(document.activeElement===e).to.be.true;const l=i(o,"focus");await u({press:"Tab"}),await l,t(e.open).to.be.false,t(document.activeElement===o).to.be.true}),it("can close and immediate shift+tab to the previous tab stop",async()=>{e.focus(),await d(),t(document.activeElement,"focuses el").to.equal(e);const n=i(e,"sp-opened");await u({press:"ArrowUp"}),await n,t(e.open,"opened").to.be.true,await r(()=>v(),"first item focused");const c=i(e,"sp-closed");e.open=!1,await c,t(e.open).to.be.false,t(document.activeElement===e).to.be.true;const l=i(a,"focus");await u({press:"Shift+Tab"}),await l,t(e.open).to.be.false,t(document.activeElement===a).to.be.true})}),it("does not open when [readonly]",async()=>{e.readonly=!0,await s(e),e.button.click(),await s(e),t(e.open).to.be.false}),it("scrolls selected into view on open",async()=>{await e.generatePopover(),e.popover.style.height="40px";const a=e.querySelector("sp-menu-item:first-child"),o=e.querySelector("sp-menu-item:last-child");o.disabled=!1,e.value=o.value,await s(e),e.open=!0,await s(e),await r(()=>v(),"first item focused");const n=c=>{const l=c.parentElement.scrollTop;return c.offsetTop-l};t(n(o)).to.be.lessThan(40),t(n(a)).to.be.lessThan(-1),o.dispatchEvent(new FocusEvent("focusin",{bubbles:!0})),o.dispatchEvent(M()),await s(e),await d(),t(n(o)).to.be.greaterThan(40),t(n(a)).to.be.greaterThan(-1)})}),describe("grouped",async()=>{const a=async()=>w(b`
684
22
  <sp-picker
685
23
  quiet
686
24
  label="I would like to use Spectrum Web Components"
@@ -702,20 +40,7 @@ export function runPickerTests() {
702
40
  <sp-menu-item value="4">In the future</sp-menu-item>
703
41
  </sp-menu-group>
704
42
  </sp-picker>
705
- `);
706
- };
707
- beforeEach(async () => {
708
- el = await groupedFixture();
709
- await elementUpdated(el);
710
- });
711
- it("selects the item with a matching value in a group", async () => {
712
- const item = el.querySelector("#should-be-selected");
713
- expect(item.selected).to.be.true;
714
- });
715
- });
716
- describe("slotted label", () => {
717
- const pickerFixture2 = async () => {
718
- const test = await fixture(html`
43
+ `);beforeEach(async()=>{e=await a(),await s(e)}),it("selects the item with a matching value in a group",async()=>{const o=e.querySelector("#should-be-selected");t(o.selected).to.be.true})}),describe("slotted label",()=>{const a=async()=>(await w(b`
719
44
  <div>
720
45
  <sp-field-label for="picker-slotted">
721
46
  Where do you live?
@@ -736,27 +61,7 @@ export function runPickerTests() {
736
61
  <sp-menu-item disabled>Make Work Path</sp-menu-item>
737
62
  </sp-picker>
738
63
  </div>
739
- `);
740
- return test.querySelector("sp-picker");
741
- };
742
- beforeEach(async () => {
743
- el = await pickerFixture2();
744
- await elementUpdated(el);
745
- });
746
- afterEach(async () => {
747
- if (el.open) {
748
- const closed = oneEvent(el, "sp-closed");
749
- el.open = false;
750
- await closed;
751
- }
752
- });
753
- it("loads accessibly w/ slotted label", async () => {
754
- await expect(el).to.be.accessible();
755
- });
756
- });
757
- describe("deprecated", () => {
758
- const pickerFixture2 = async () => {
759
- const test = await fixture(html`
64
+ `)).querySelector("sp-picker");beforeEach(async()=>{e=await a(),await s(e)}),afterEach(async()=>{if(e.open){const o=i(e,"sp-closed");e.open=!1,await o}}),it("loads accessibly w/ slotted label",async()=>{await t(e).to.be.accessible()})}),describe("deprecated",()=>{const a=async()=>(await w(b`
760
65
  <div>
761
66
  <sp-field-label for="picker-deprecated">
762
67
  Where do you live?
@@ -780,121 +85,9 @@ export function runPickerTests() {
780
85
  </sp-menu>
781
86
  </sp-picker>
782
87
  </div>
783
- `);
784
- return test.querySelector("sp-picker");
785
- };
786
- describe("Dev mode", () => {
787
- it("warns in Dev Mode of deprecated `<sp-menu>` usage", async () => {
788
- const consoleWarnStub = stub(console, "warn");
789
- el = await pickerFixture2();
790
- await elementUpdated(el);
791
- expect(consoleWarnStub.called).to.be.true;
792
- const spyCall = consoleWarnStub.getCall(0);
793
- expect(spyCall.args.at(0).includes("<sp-menu>"), "confirm <sp-menu>-centric message").to.be.true;
794
- expect(spyCall.args.at(-1), "confirm `data` shape").to.deep.equal({
795
- data: {
796
- localName: "sp-picker",
797
- type: "api",
798
- level: "deprecation"
799
- }
800
- });
801
- consoleWarnStub.restore();
802
- if (el.open) {
803
- const closed = oneEvent(el, "sp-closed");
804
- el.open = false;
805
- await closed;
806
- }
807
- });
808
- });
809
- describe("Dev mode ignored", () => {
810
- const { ignoreWarningLocalNames } = window.__swc;
811
- before(() => {
812
- window.__swc.ignoreWarningLocalNames = {
813
- "sp-picker": true
814
- };
815
- });
816
- before(() => {
817
- window.__swc.ignoreWarningLocalNames = ignoreWarningLocalNames;
818
- });
819
- beforeEach(async () => {
820
- el = await pickerFixture2();
821
- await elementUpdated(el);
822
- });
823
- afterEach(async () => {
824
- if (el.open) {
825
- const closed = oneEvent(el, "sp-closed");
826
- el.open = false;
827
- await closed;
828
- }
829
- });
830
- it("selects with deprecated syntax", async () => {
831
- var _a, _b;
832
- const secondItem = el.querySelector("sp-menu-item:nth-of-type(2)");
833
- const opened = oneEvent(el, "sp-opened");
834
- el.button.click();
835
- await opened;
836
- await elementUpdated(el);
837
- expect(el.open).to.be.true;
838
- expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
839
- expect(el.value).to.equal("");
840
- const closed = oneEvent(el, "sp-closed");
841
- secondItem.click();
842
- await closed;
843
- expect(el.open).to.be.false;
844
- expect((_b = el.selectedItem) == null ? void 0 : _b.itemText).to.equal("Select Inverse");
845
- expect(el.value).to.equal("option-2");
846
- });
847
- });
848
- });
849
- testForLitDevWarnings(async () => await pickerFixture());
850
- it('manages its "name" value in the accessibility tree when [icons-only]', async () => {
851
- const test = await fixture(html`
852
- <div>${iconsOnly({})}</div>
853
- `);
854
- const el2 = test.querySelector("sp-picker");
855
- await elementUpdated(el2);
856
- let snapshot = await a11ySnapshot({});
857
- expect(findAccessibilityNode(snapshot, (node) => node.name === "Choose an action type... Delete"), "`name` is the label text").to.not.be.null;
858
- el2.value = "2";
859
- await elementUpdated(el2);
860
- snapshot = await a11ySnapshot({});
861
- expect(findAccessibilityNode(snapshot, (node) => node.name === "Choose an action type... Copy"), "`name` is the label text plus the selected item text").to.not.be.null;
862
- });
863
- it("toggles between pickers", async () => {
864
- const el2 = await pickerFixture();
865
- const el1 = await pickerFixture();
866
- el1.id = "away";
867
- el2.id = "other";
868
- await Promise.all([elementUpdated(el1), elementUpdated(el2)]);
869
- expect(el1.open, "closed 1").to.be.false;
870
- expect(el2.open, "closed 1").to.be.false;
871
- let open = oneEvent(el1, "sp-opened");
872
- el1.click();
873
- await open;
874
- expect(el1.open).to.be.true;
875
- expect(el2.open).to.be.false;
876
- open = oneEvent(el2, "sp-opened");
877
- let closed = oneEvent(el1, "sp-closed");
878
- el2.click();
879
- await Promise.all([open, closed]);
880
- expect(el1.open).to.be.false;
881
- expect(el2.open).to.be.true;
882
- open = oneEvent(el1, "sp-opened");
883
- closed = oneEvent(el2, "sp-closed");
884
- el1.click();
885
- await Promise.all([open, closed]);
886
- expect(el1.open).to.be.true;
887
- expect(el2.open).to.be.false;
888
- closed = oneEvent(el1, "sp-closed");
889
- sendKeys({
890
- press: "Escape"
891
- });
892
- await closed;
893
- expect(el1.open).to.be.false;
894
- });
895
- it("displays selected item text by default", async () => {
896
- var _a, _b, _c, _d;
897
- const el2 = await fixture(html`
88
+ `)).querySelector("sp-picker");describe("Dev mode",()=>{it("warns in Dev Mode of deprecated `<sp-menu>` usage",async()=>{const o=x(console,"warn");e=await a(),await s(e),t(o.called).to.be.true;const n=o.getCall(0);if(t(n.args.at(0).includes("<sp-menu>"),"confirm <sp-menu>-centric message").to.be.true,t(n.args.at(-1),"confirm `data` shape").to.deep.equal({data:{localName:"sp-picker",type:"api",level:"deprecation"}}),o.restore(),e.open){const c=i(e,"sp-closed");e.open=!1,await c}})}),describe("Dev mode ignored",()=>{const{ignoreWarningLocalNames:o}=window.__swc;before(()=>{window.__swc.ignoreWarningLocalNames={"sp-picker":!0}}),before(()=>{window.__swc.ignoreWarningLocalNames=o}),beforeEach(async()=>{e=await a(),await s(e)}),afterEach(async()=>{if(e.open){const n=i(e,"sp-closed");e.open=!1,await n}}),it("selects with deprecated syntax",async()=>{var p,m;const n=e.querySelector("sp-menu-item:nth-of-type(2)"),c=i(e,"sp-opened");e.button.click(),await c,await s(e),t(e.open).to.be.true,t((p=e.selectedItem)==null?void 0:p.itemText).to.be.undefined,t(e.value).to.equal("");const l=i(e,"sp-closed");n.click(),await l,t(e.open).to.be.false,t((m=e.selectedItem)==null?void 0:m.itemText).to.equal("Select Inverse"),t(e.value).to.equal("option-2")})})}),P(async()=>await S()),it('manages its "name" value in the accessibility tree when [icons-only]',async()=>{const o=(await w(b`
89
+ <div>${L({})}</div>
90
+ `)).querySelector("sp-picker");await s(o);let n=await q({});t(g(n,c=>c.name==="Choose an action type... Delete"),"`name` is the label text").to.not.be.null,o.value="2",await s(o),n=await q({}),t(g(n,c=>c.name==="Choose an action type... Copy"),"`name` is the label text plus the selected item text").to.not.be.null}),it("toggles between pickers",async()=>{const a=await S(),o=await S();o.id="away",a.id="other",await Promise.all([s(o),s(a)]),t(o.open,"closed 1").to.be.false,t(a.open,"closed 1").to.be.false;let n=i(o,"sp-opened");o.click(),await n,t(o.open).to.be.true,t(a.open).to.be.false,n=i(a,"sp-opened");let c=i(o,"sp-closed");a.click(),await Promise.all([n,c]),t(o.open).to.be.false,t(a.open).to.be.true,n=i(o,"sp-opened"),c=i(a,"sp-closed"),o.click(),await Promise.all([n,c]),t(o.open).to.be.true,t(a.open).to.be.false,c=i(o,"sp-closed"),u({press:"Escape"}),await c,t(o.open).to.be.false}),it("displays selected item text by default",async()=>{var l,p,m,f;const a=await w(b`
898
91
  <sp-picker
899
92
  value="inverse"
900
93
  label="Select a Country with a very long label, too long in fact"
@@ -907,31 +100,7 @@ export function runPickerTests() {
907
100
  <sp-menu-item>Save Selection</sp-menu-item>
908
101
  <sp-menu-item disabled>Make Work Path</sp-menu-item>
909
102
  </sp-picker>
910
- `);
911
- await elementUpdated(el2);
912
- await waitUntil(() => {
913
- var _a2;
914
- return ((_a2 = el2.selectedItem) == null ? void 0 : _a2.itemText) === "Select Inverse";
915
- }, `Selected Item Text: ${(_a = el2.selectedItem) == null ? void 0 : _a.itemText}`);
916
- const firstItem = el2.querySelector("sp-menu-item:nth-of-type(1)");
917
- const secondItem = el2.querySelector("sp-menu-item:nth-of-type(2)");
918
- expect(el2.value).to.equal("inverse");
919
- expect((_b = el2.selectedItem) == null ? void 0 : _b.itemText).to.equal("Select Inverse");
920
- el2.focus();
921
- await elementUpdated(el2);
922
- expect(el2 === document.activeElement, `activeElement is ${(_c = document.activeElement) == null ? void 0 : _c.localName}`).to.be.true;
923
- const opened = oneEvent(el2, "sp-opened");
924
- sendKeys({ press: "Enter" });
925
- await opened;
926
- await elementUpdated(el2.optionsMenu);
927
- expect(el2.optionsMenu === document.activeElement, `activeElement is ${(_d = document.activeElement) == null ? void 0 : _d.localName}`).to.be.true;
928
- expect(firstItem.focused, 'firstItem NOT "focused"').to.be.false;
929
- expect(secondItem.focused, 'secondItem "focused"').to.be.true;
930
- expect(el2.optionsMenu.getAttribute("aria-activedescendant")).to.equal(secondItem.id);
931
- });
932
- it("resets value when item not available", async () => {
933
- var _a;
934
- const el2 = await fixture(html`
103
+ `);await s(a),await r(()=>{var y;return((y=a.selectedItem)==null?void 0:y.itemText)==="Select Inverse"},`Selected Item Text: ${(l=a.selectedItem)==null?void 0:l.itemText}`);const o=a.querySelector("sp-menu-item:nth-of-type(1)"),n=a.querySelector("sp-menu-item:nth-of-type(2)");t(a.value).to.equal("inverse"),t((p=a.selectedItem)==null?void 0:p.itemText).to.equal("Select Inverse"),a.focus(),await s(a),t(a===document.activeElement,`activeElement is ${(m=document.activeElement)==null?void 0:m.localName}`).to.be.true;const c=i(a,"sp-opened");u({press:"Enter"}),await c,await s(a.optionsMenu),t(a.optionsMenu===document.activeElement,`activeElement is ${(f=document.activeElement)==null?void 0:f.localName}`).to.be.true,t(o.focused,'firstItem NOT "focused"').to.be.false,t(n.focused,'secondItem "focused"').to.be.true,t(a.optionsMenu.getAttribute("aria-activedescendant")).to.equal(n.id)}),it("resets value when item not available",async()=>{var o;const a=await w(b`
935
104
  <sp-picker
936
105
  value="missing"
937
106
  label="Select a Country with a very long label, too long in fact"
@@ -944,74 +113,24 @@ export function runPickerTests() {
944
113
  <sp-menu-item>Save Selection</sp-menu-item>
945
114
  <sp-menu-item disabled>Make Work Path</sp-menu-item>
946
115
  </sp-picker>
947
- `);
948
- await elementUpdated(el2);
949
- await waitUntil(() => el2.value === "");
950
- expect(el2.value).to.equal("");
951
- expect((_a = el2.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
952
- });
953
- it("allows event listeners on child items", async () => {
954
- const mouseenterSpy = spy();
955
- const handleMouseenter = () => mouseenterSpy();
956
- const el2 = await fixture(html`
116
+ `);await s(a),await r(()=>a.value===""),t(a.value).to.equal(""),t((o=a.selectedItem)==null?void 0:o.itemText).to.be.undefined}),it("allows event listeners on child items",async()=>{const a=h(),n=await w(b`
957
117
  <sp-picker
958
118
  label="Select a Country with a very long label, too long in fact"
959
119
  >
960
120
  <sp-menu-item
961
121
  value="deselect"
962
- @mouseenter=${handleMouseenter}
122
+ @mouseenter=${()=>a()}
963
123
  >
964
124
  Deselect Text
965
125
  </sp-menu-item>
966
126
  </sp-picker>
967
- `);
968
- await elementUpdated(el2);
969
- const hoverEl = el2.querySelector("sp-menu-item");
970
- const opened = oneEvent(el2, "sp-opened");
971
- el2.open = true;
972
- await opened;
973
- await elementUpdated(el2);
974
- expect(el2.open).to.be.true;
975
- hoverEl.dispatchEvent(new MouseEvent("mouseenter"));
976
- await elementUpdated(el2);
977
- expect(el2.open).to.be.true;
978
- const closed = oneEvent(el2, "sp-closed");
979
- el2.open = false;
980
- await closed;
981
- await elementUpdated(el2);
982
- expect(el2.open).to.be.false;
983
- expect(mouseenterSpy.calledOnce).to.be.true;
984
- });
985
- it("dispatches events on open/close", async () => {
986
- const openedSpy = spy();
987
- const closedSpy = spy();
988
- const handleOpenedSpy = (event) => openedSpy(event);
989
- const handleClosedSpy = (event) => closedSpy(event);
990
- const el2 = await fixture(html`
127
+ `);await s(n);const c=n.querySelector("sp-menu-item"),l=i(n,"sp-opened");n.open=!0,await l,await s(n),t(n.open).to.be.true,c.dispatchEvent(new MouseEvent("mouseenter")),await s(n),t(n.open).to.be.true;const p=i(n,"sp-closed");n.open=!1,await p,await s(n),t(n.open).to.be.false,t(a.calledOnce).to.be.true}),it("dispatches events on open/close",async()=>{const a=h(),o=h(),l=await w(b`
991
128
  <sp-picker
992
129
  label="Select a Country with a very long label, too long in fact"
993
- @sp-opened=${handleOpenedSpy}
994
- @sp-closed=${handleClosedSpy}
130
+ @sp-opened=${E=>a(E)}
131
+ @sp-closed=${E=>o(E)}
995
132
  >
996
133
  <sp-menu-item value="deselect">Deselect Text</sp-menu-item>
997
134
  </sp-picker>
998
- `);
999
- await elementUpdated(el2);
1000
- const opened = oneEvent(el2, "sp-opened");
1001
- el2.open = true;
1002
- await opened;
1003
- await elementUpdated(el2);
1004
- expect(openedSpy.calledOnce).to.be.true;
1005
- expect(closedSpy.calledOnce).to.be.false;
1006
- const openedEvent = openedSpy.args[0][0];
1007
- expect(openedEvent.detail.interaction).to.equal("modal");
1008
- const closed = oneEvent(el2, "sp-closed");
1009
- el2.open = false;
1010
- await closed;
1011
- await elementUpdated(el2);
1012
- expect(closedSpy.calledOnce).to.be.true;
1013
- const closedEvent = closedSpy.args[0][0];
1014
- expect(closedEvent.detail.interaction).to.equal("modal");
1015
- });
1016
- }
135
+ `);await s(l);const p=i(l,"sp-opened");l.open=!0,await p,await s(l),t(a.calledOnce).to.be.true,t(o.calledOnce).to.be.false;const m=a.args[0][0];t(m.detail.interaction).to.equal("modal");const f=i(l,"sp-closed");l.open=!1,await f,await s(l),t(o.calledOnce).to.be.true;const y=o.args[0][0];t(y.detail.interaction).to.equal("modal")})}
1017
136
  //# sourceMappingURL=index.js.map