@spectrum-web-components/picker 0.15.3-overlay.17 → 0.30.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/custom-elements.json +1730 -0
- package/package.json +13 -13
- package/sp-picker.dev.js +2 -1
- package/sp-picker.dev.js.map +2 -2
- package/sp-picker.js +1 -1
- package/sp-picker.js.map +3 -3
- package/src/Picker.d.ts +31 -18
- package/src/Picker.dev.js +170 -124
- package/src/Picker.dev.js.map +3 -3
- package/src/Picker.js +16 -30
- package/src/Picker.js.map +3 -3
- package/src/picker.css.dev.js +2 -2
- package/src/picker.css.dev.js.map +1 -1
- package/src/picker.css.js +2 -2
- package/src/picker.css.js.map +1 -1
- package/src/spectrum-picker.css.dev.js +1 -1
- package/src/spectrum-picker.css.dev.js.map +1 -1
- package/src/spectrum-picker.css.js +1 -1
- package/src/spectrum-picker.css.js.map +1 -1
- package/sync/index.d.ts +1 -4
- package/sync/index.dev.js +6 -1
- package/sync/index.dev.js.map +2 -2
- package/sync/index.js +1 -1
- package/sync/index.js.map +3 -3
- package/test/index.js +141 -123
- package/test/index.js.map +2 -2
- package/test/picker-reparenting.test.js +18 -11
- package/test/picker-reparenting.test.js.map +2 -2
- package/test/picker-responsive.test.js +2 -3
- package/test/picker-responsive.test.js.map +2 -2
- package/test/picker.test.js +1 -1
- package/test/picker.test.js.map +2 -2
package/test/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import {
|
|
3
|
-
aTimeout,
|
|
4
3
|
elementUpdated,
|
|
5
4
|
expect,
|
|
6
5
|
fixture,
|
|
@@ -28,19 +27,18 @@ import {
|
|
|
28
27
|
import { iconsOnly } from "../stories/picker.stories.js";
|
|
29
28
|
import { sendMouse } from "../../../test/plugins/browser.js";
|
|
30
29
|
import { ignoreResizeObserverLoopError } from "../../../test/testing-helpers.js";
|
|
31
|
-
import "@spectrum-web-components/
|
|
32
|
-
import "@spectrum-web-components/theme/src/themes.js";
|
|
30
|
+
import { isWebKit } from "@spectrum-web-components/shared/src/platform.js";
|
|
33
31
|
ignoreResizeObserverLoopError(before, after);
|
|
34
|
-
const isMenuActiveElement = function(
|
|
32
|
+
const isMenuActiveElement = function() {
|
|
35
33
|
var _a;
|
|
36
|
-
return ((_a =
|
|
34
|
+
return ((_a = document.activeElement) == null ? void 0 : _a.localName) === "sp-menu";
|
|
37
35
|
};
|
|
38
36
|
export function runPickerTests() {
|
|
39
37
|
let el;
|
|
40
38
|
const pickerFixture = async () => {
|
|
41
39
|
const test = await fixture(
|
|
42
40
|
html`
|
|
43
|
-
<
|
|
41
|
+
<div>
|
|
44
42
|
<sp-field-label for="picker">
|
|
45
43
|
Where do you live?
|
|
46
44
|
</sp-field-label>
|
|
@@ -58,7 +56,7 @@ export function runPickerTests() {
|
|
|
58
56
|
<sp-menu-item>Save Selection</sp-menu-item>
|
|
59
57
|
<sp-menu-item disabled>Make Work Path</sp-menu-item>
|
|
60
58
|
</sp-picker>
|
|
61
|
-
</
|
|
59
|
+
</div>
|
|
62
60
|
`
|
|
63
61
|
);
|
|
64
62
|
return test.querySelector("sp-picker");
|
|
@@ -68,6 +66,13 @@ export function runPickerTests() {
|
|
|
68
66
|
el = await pickerFixture();
|
|
69
67
|
await elementUpdated(el);
|
|
70
68
|
});
|
|
69
|
+
afterEach(async () => {
|
|
70
|
+
if (el.open) {
|
|
71
|
+
const closed = oneEvent(el, "sp-closed");
|
|
72
|
+
el.open = false;
|
|
73
|
+
await closed;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
71
76
|
it("loads accessibly", async () => {
|
|
72
77
|
await expect(el).to.be.accessible();
|
|
73
78
|
});
|
|
@@ -76,7 +81,7 @@ export function runPickerTests() {
|
|
|
76
81
|
el.open = true;
|
|
77
82
|
await opened;
|
|
78
83
|
expect(el.open).to.be.true;
|
|
79
|
-
const accessibleCloseButton =
|
|
84
|
+
const accessibleCloseButton = document.querySelector(
|
|
80
85
|
".visually-hidden button"
|
|
81
86
|
);
|
|
82
87
|
const closed = oneEvent(el, "sp-closed");
|
|
@@ -85,13 +90,10 @@ export function runPickerTests() {
|
|
|
85
90
|
expect(el.open).to.be.false;
|
|
86
91
|
});
|
|
87
92
|
it("accepts new selected item content", async () => {
|
|
88
|
-
await nextFrame();
|
|
89
|
-
await nextFrame();
|
|
90
93
|
const option2 = el.querySelector('[value="option-2"');
|
|
91
94
|
el.value = "option-2";
|
|
92
95
|
await elementUpdated(option2);
|
|
93
96
|
await elementUpdated(el);
|
|
94
|
-
await aTimeout(150);
|
|
95
97
|
expect(el.value).to.equal("option-2");
|
|
96
98
|
expect((el.button.textContent || "").trim()).to.equal(
|
|
97
99
|
"Select Inverse"
|
|
@@ -112,11 +114,9 @@ export function runPickerTests() {
|
|
|
112
114
|
expect((el.button.textContent || "").trim()).to.equal(newLabel2);
|
|
113
115
|
});
|
|
114
116
|
it("accepts new selected item content when open", async () => {
|
|
115
|
-
await nextFrame();
|
|
116
117
|
const option2 = el.querySelector('[value="option-2"');
|
|
117
118
|
el.value = "option-2";
|
|
118
119
|
await elementUpdated(el);
|
|
119
|
-
await aTimeout(150);
|
|
120
120
|
expect(el.value).to.equal("option-2");
|
|
121
121
|
expect((el.button.textContent || "").trim()).to.equal(
|
|
122
122
|
"Select Inverse"
|
|
@@ -137,10 +137,8 @@ export function runPickerTests() {
|
|
|
137
137
|
);
|
|
138
138
|
});
|
|
139
139
|
it("unsets value when children removed", async () => {
|
|
140
|
-
await nextFrame();
|
|
141
140
|
el.value = "option-2";
|
|
142
141
|
await elementUpdated(el);
|
|
143
|
-
await aTimeout(150);
|
|
144
142
|
expect(el.value).to.equal("option-2");
|
|
145
143
|
expect((el.button.textContent || "").trim()).to.equal(
|
|
146
144
|
"Select Inverse"
|
|
@@ -154,14 +152,8 @@ export function runPickerTests() {
|
|
|
154
152
|
});
|
|
155
153
|
await Promise.all(removals);
|
|
156
154
|
await elementUpdated(el);
|
|
157
|
-
await nextFrame();
|
|
158
|
-
await aTimeout(150);
|
|
159
|
-
expect(el.optionsMenu.childItems.length).to.equal(0);
|
|
160
|
-
if ("showPopover" in document.createElement("div")) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
expect((el.button.textContent || "").trim()).to.equal("");
|
|
164
155
|
expect(el.value).to.equal("");
|
|
156
|
+
expect((el.button.textContent || "").trim()).to.equal("");
|
|
165
157
|
});
|
|
166
158
|
it("accepts a new item and value at the same time", async () => {
|
|
167
159
|
el.value = "option-2";
|
|
@@ -184,7 +176,7 @@ export function runPickerTests() {
|
|
|
184
176
|
item.value = "option-new";
|
|
185
177
|
item.textContent = "New Option";
|
|
186
178
|
el.append(item);
|
|
187
|
-
await
|
|
179
|
+
await elementUpdated(item);
|
|
188
180
|
await elementUpdated(el);
|
|
189
181
|
let opened = oneEvent(el, "sp-opened");
|
|
190
182
|
el.open = true;
|
|
@@ -202,7 +194,6 @@ export function runPickerTests() {
|
|
|
202
194
|
expect(el.value, "second time").to.equal("option-new");
|
|
203
195
|
});
|
|
204
196
|
it('manages its "name" value in the accessibility tree', async () => {
|
|
205
|
-
await nextFrame();
|
|
206
197
|
let snapshot = await a11ySnapshot({});
|
|
207
198
|
expect(
|
|
208
199
|
findAccessibilityNode(
|
|
@@ -213,8 +204,6 @@ export function runPickerTests() {
|
|
|
213
204
|
).to.not.be.null;
|
|
214
205
|
el.value = "option-2";
|
|
215
206
|
await elementUpdated(el);
|
|
216
|
-
await nextFrame();
|
|
217
|
-
await nextFrame();
|
|
218
207
|
snapshot = await a11ySnapshot({});
|
|
219
208
|
expect(
|
|
220
209
|
findAccessibilityNode(
|
|
@@ -251,7 +240,6 @@ export function runPickerTests() {
|
|
|
251
240
|
await expect(el).to.be.accessible();
|
|
252
241
|
});
|
|
253
242
|
it("opens with visible focus on a menu item on `DownArrow`", async () => {
|
|
254
|
-
var _a, _b;
|
|
255
243
|
const firstItem = el.querySelector("sp-menu-item");
|
|
256
244
|
await elementUpdated(el);
|
|
257
245
|
expect(firstItem.focused, "should not visually focused").to.be.false;
|
|
@@ -270,24 +258,12 @@ export function runPickerTests() {
|
|
|
270
258
|
});
|
|
271
259
|
await closed;
|
|
272
260
|
expect(el.open).to.be.false;
|
|
273
|
-
|
|
274
|
-
document.activeElement === el,
|
|
275
|
-
`focused ${(_a = document.activeElement) == null ? void 0 : _a.localName} instead of back on Picker`
|
|
276
|
-
).to.be.true;
|
|
277
|
-
expect(
|
|
278
|
-
el.shadowRoot.activeElement === el.button,
|
|
279
|
-
`focused ${(_b = el.shadowRoot.activeElement) == null ? void 0 : _b.localName} instead of back on button`
|
|
280
|
-
).to.be.true;
|
|
281
|
-
await waitUntil(
|
|
282
|
-
() => !firstItem.focused,
|
|
283
|
-
"finally, not visually focused"
|
|
284
|
-
);
|
|
261
|
+
await waitUntil(() => !firstItem.focused, "not visually focused");
|
|
285
262
|
});
|
|
286
|
-
it("opens
|
|
287
|
-
await nextFrame();
|
|
288
|
-
await nextFrame();
|
|
263
|
+
it("opens without visible focus on a menu item on click", async () => {
|
|
289
264
|
const firstItem = el.querySelector("sp-menu-item");
|
|
290
|
-
|
|
265
|
+
await elementUpdated(el);
|
|
266
|
+
const boundingRect = el.getBoundingClientRect();
|
|
291
267
|
expect(firstItem.focused, "not visually focused").to.be.false;
|
|
292
268
|
const opened = oneEvent(el, "sp-opened");
|
|
293
269
|
sendMouse({
|
|
@@ -302,6 +278,7 @@ export function runPickerTests() {
|
|
|
302
278
|
]
|
|
303
279
|
});
|
|
304
280
|
await opened;
|
|
281
|
+
await elementUpdated(el);
|
|
305
282
|
expect(el.open).to.be.true;
|
|
306
283
|
expect(firstItem.focused, "still not visually focused").to.be.false;
|
|
307
284
|
});
|
|
@@ -320,15 +297,11 @@ export function runPickerTests() {
|
|
|
320
297
|
document.body.append(other);
|
|
321
298
|
await elementUpdated(el);
|
|
322
299
|
expect(el.open).to.be.false;
|
|
323
|
-
const opened = oneEvent(el, "sp-opened");
|
|
324
300
|
el.click();
|
|
325
|
-
await opened;
|
|
326
301
|
await elementUpdated(el);
|
|
327
302
|
expect(el.open).to.be.true;
|
|
328
|
-
const closed = oneEvent(el, "sp-closed");
|
|
329
303
|
other.click();
|
|
330
|
-
closed;
|
|
331
|
-
await elementUpdated(el);
|
|
304
|
+
await waitUntil(() => !el.open, "closed");
|
|
332
305
|
other.remove();
|
|
333
306
|
});
|
|
334
307
|
it("selects", async () => {
|
|
@@ -340,6 +313,7 @@ export function runPickerTests() {
|
|
|
340
313
|
const opened = oneEvent(el, "sp-opened");
|
|
341
314
|
button.click();
|
|
342
315
|
await opened;
|
|
316
|
+
await elementUpdated(el);
|
|
343
317
|
expect(el.open).to.be.true;
|
|
344
318
|
expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
|
|
345
319
|
expect(el.value).to.equal("");
|
|
@@ -359,27 +333,31 @@ export function runPickerTests() {
|
|
|
359
333
|
"sp-menu-item:nth-of-type(2)"
|
|
360
334
|
);
|
|
361
335
|
const button = el.button;
|
|
362
|
-
|
|
336
|
+
const opened = oneEvent(el, "sp-opened");
|
|
363
337
|
button.click();
|
|
364
338
|
await opened;
|
|
339
|
+
await nextFrame();
|
|
365
340
|
expect(el.open).to.be.true;
|
|
366
341
|
expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
|
|
367
342
|
expect(el.value).to.equal("");
|
|
368
|
-
|
|
343
|
+
const closed = oneEvent(el, "sp-closed");
|
|
369
344
|
secondItem.click();
|
|
370
345
|
await closed;
|
|
346
|
+
await nextFrame();
|
|
371
347
|
expect(el.open).to.be.false;
|
|
372
348
|
expect((_b = el.selectedItem) == null ? void 0 : _b.itemText).to.equal("Select Inverse");
|
|
373
349
|
expect(el.value).to.equal("option-2");
|
|
374
|
-
|
|
350
|
+
const opened2 = oneEvent(el, "sp-opened");
|
|
375
351
|
button.click();
|
|
376
|
-
await
|
|
352
|
+
await opened2;
|
|
353
|
+
await nextFrame();
|
|
377
354
|
expect(el.open).to.be.true;
|
|
378
355
|
expect((_c = el.selectedItem) == null ? void 0 : _c.itemText).to.equal("Select Inverse");
|
|
379
356
|
expect(el.value).to.equal("option-2");
|
|
380
|
-
|
|
357
|
+
const closed2 = oneEvent(el, "sp-closed");
|
|
381
358
|
firstItem.click();
|
|
382
|
-
await
|
|
359
|
+
await closed2;
|
|
360
|
+
await nextFrame();
|
|
383
361
|
expect(el.open).to.be.false;
|
|
384
362
|
expect((_d = el.selectedItem) == null ? void 0 : _d.itemText).to.equal("Deselect");
|
|
385
363
|
expect(el.value).to.equal("Deselect");
|
|
@@ -387,6 +365,7 @@ export function runPickerTests() {
|
|
|
387
365
|
it("dispatches bubbling and composed events", async () => {
|
|
388
366
|
const changeSpy = spy();
|
|
389
367
|
const parent = el.parentElement;
|
|
368
|
+
parent.attachShadow({ mode: "open" });
|
|
390
369
|
parent.shadowRoot.append(el);
|
|
391
370
|
const secondItem = el.querySelector(
|
|
392
371
|
"sp-menu-item:nth-of-type(2)"
|
|
@@ -396,9 +375,11 @@ export function runPickerTests() {
|
|
|
396
375
|
const opened = oneEvent(el, "sp-opened");
|
|
397
376
|
el.open = true;
|
|
398
377
|
await opened;
|
|
378
|
+
await elementUpdated(el);
|
|
399
379
|
const closed = oneEvent(el, "sp-closed");
|
|
400
380
|
secondItem.click();
|
|
401
381
|
await closed;
|
|
382
|
+
await elementUpdated(el);
|
|
402
383
|
expect(el.value).to.equal(secondItem.value);
|
|
403
384
|
expect(changeSpy.calledOnce).to.be.true;
|
|
404
385
|
});
|
|
@@ -409,9 +390,10 @@ export function runPickerTests() {
|
|
|
409
390
|
"sp-menu-item:nth-of-type(2)"
|
|
410
391
|
);
|
|
411
392
|
const button = el.button;
|
|
412
|
-
|
|
393
|
+
let opened = oneEvent(el, "sp-opened");
|
|
413
394
|
button.click();
|
|
414
395
|
await opened;
|
|
396
|
+
await elementUpdated(el);
|
|
415
397
|
expect(el.open).to.be.true;
|
|
416
398
|
expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
|
|
417
399
|
expect(el.value).to.equal("");
|
|
@@ -420,12 +402,14 @@ export function runPickerTests() {
|
|
|
420
402
|
event.preventDefault();
|
|
421
403
|
preventChangeSpy();
|
|
422
404
|
});
|
|
405
|
+
const closed = oneEvent(el, "sp-closed");
|
|
406
|
+
opened = oneEvent(el, "sp-opened");
|
|
423
407
|
secondItem.click();
|
|
424
|
-
await
|
|
425
|
-
await
|
|
408
|
+
await closed;
|
|
409
|
+
await opened;
|
|
410
|
+
await elementUpdated(el);
|
|
426
411
|
expect(preventChangeSpy.calledOnce).to.be.true;
|
|
427
412
|
expect(secondItem.selected, "selection prevented").to.be.false;
|
|
428
|
-
expect(el.open).to.be.true;
|
|
429
413
|
});
|
|
430
414
|
it("can throw focus after `change`", async () => {
|
|
431
415
|
var _a;
|
|
@@ -468,15 +452,20 @@ export function runPickerTests() {
|
|
|
468
452
|
button.dispatchEvent(tEvent());
|
|
469
453
|
await elementUpdated(el);
|
|
470
454
|
expect(el.open, "still closed").to.be.false;
|
|
471
|
-
const opened = oneEvent(el, "sp-opened");
|
|
472
455
|
button.dispatchEvent(arrowUpEvent());
|
|
473
456
|
await elementUpdated(el);
|
|
474
457
|
expect(el.open, "open by ArrowUp").to.be.true;
|
|
475
|
-
await
|
|
476
|
-
|
|
458
|
+
await waitUntil(
|
|
459
|
+
() => document.querySelector("active-overlay") !== null,
|
|
460
|
+
"an active-overlay has been inserted on the page"
|
|
461
|
+
);
|
|
477
462
|
button.dispatchEvent(escapeEvent());
|
|
478
|
-
await
|
|
479
|
-
|
|
463
|
+
await elementUpdated(el);
|
|
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
|
+
);
|
|
480
469
|
});
|
|
481
470
|
it("opens on ArrowDown", async () => {
|
|
482
471
|
var _a, _b;
|
|
@@ -490,18 +479,19 @@ export function runPickerTests() {
|
|
|
490
479
|
const opened = oneEvent(el, "sp-opened");
|
|
491
480
|
button.dispatchEvent(arrowDownEvent());
|
|
492
481
|
await opened;
|
|
482
|
+
await elementUpdated(el);
|
|
493
483
|
expect(el.open, "open by ArrowDown").to.be.true;
|
|
494
484
|
expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
|
|
495
485
|
expect(el.value).to.equal("");
|
|
496
486
|
const closed = oneEvent(el, "sp-closed");
|
|
497
487
|
firstItem.click();
|
|
498
488
|
await closed;
|
|
489
|
+
await elementUpdated(el);
|
|
499
490
|
expect(el.open).to.be.false;
|
|
500
491
|
expect((_b = el.selectedItem) == null ? void 0 : _b.itemText).to.equal("Deselect");
|
|
501
492
|
expect(el.value).to.equal("Deselect");
|
|
502
493
|
});
|
|
503
494
|
it("quick selects on ArrowLeft/Right", async () => {
|
|
504
|
-
await nextFrame();
|
|
505
495
|
const selectionSpy = spy();
|
|
506
496
|
el.addEventListener("change", (event) => {
|
|
507
497
|
const { value } = event.target;
|
|
@@ -529,7 +519,6 @@ export function runPickerTests() {
|
|
|
529
519
|
expect(selectionSpy.calledWith("Make Work Path")).to.be.false;
|
|
530
520
|
});
|
|
531
521
|
it("quick selects first item on ArrowRight when no value", async () => {
|
|
532
|
-
await nextFrame();
|
|
533
522
|
const selectionSpy = spy();
|
|
534
523
|
el.addEventListener("change", (event) => {
|
|
535
524
|
const { value } = event.target;
|
|
@@ -547,10 +536,6 @@ export function runPickerTests() {
|
|
|
547
536
|
});
|
|
548
537
|
it("refocuses on list when open", async () => {
|
|
549
538
|
const firstItem = el.querySelector("sp-menu-item");
|
|
550
|
-
const thirdItem = el.querySelector(
|
|
551
|
-
"sp-menu-item:nth-of-type(3)"
|
|
552
|
-
);
|
|
553
|
-
const button = el.button;
|
|
554
539
|
const input = document.createElement("input");
|
|
555
540
|
el.insertAdjacentElement("afterend", input);
|
|
556
541
|
el.focus();
|
|
@@ -558,41 +543,44 @@ export function runPickerTests() {
|
|
|
558
543
|
expect(document.activeElement === input).to.be.true;
|
|
559
544
|
await sendKeys({ press: "Shift+Tab" });
|
|
560
545
|
expect(document.activeElement === el).to.be.true;
|
|
546
|
+
await sendKeys({ press: "Enter" });
|
|
561
547
|
const opened = oneEvent(el, "sp-opened");
|
|
562
|
-
|
|
548
|
+
el.open = true;
|
|
563
549
|
await opened;
|
|
564
550
|
await elementUpdated(el);
|
|
565
551
|
await waitUntil(
|
|
566
552
|
() => firstItem.focused,
|
|
567
553
|
"The first items should have become focused visually."
|
|
568
554
|
);
|
|
569
|
-
|
|
570
|
-
await
|
|
571
|
-
expect(
|
|
572
|
-
button.focus();
|
|
573
|
-
expect(isMenuActiveElement(el)).to.be.false;
|
|
555
|
+
el.blur();
|
|
556
|
+
await elementUpdated(el);
|
|
557
|
+
expect(el.open).to.be.true;
|
|
574
558
|
el.focus();
|
|
575
559
|
await elementUpdated(el);
|
|
576
560
|
await waitUntil(
|
|
577
|
-
() => isMenuActiveElement(
|
|
561
|
+
() => isMenuActiveElement(),
|
|
578
562
|
"first item refocused"
|
|
579
563
|
);
|
|
580
|
-
expect(
|
|
581
|
-
expect(
|
|
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;
|
|
582
569
|
});
|
|
583
|
-
it("
|
|
584
|
-
const input = document.createElement("input");
|
|
585
|
-
el.insertAdjacentElement("afterend", input);
|
|
586
|
-
const opened = oneEvent(el, "sp-opened");
|
|
570
|
+
it("does not allow tabing to close", async () => {
|
|
587
571
|
el.open = true;
|
|
588
|
-
await
|
|
589
|
-
await nextFrame();
|
|
572
|
+
await elementUpdated(el);
|
|
590
573
|
expect(el.open).to.be.true;
|
|
591
574
|
el.focus();
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
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;
|
|
596
584
|
});
|
|
597
585
|
describe("tab order", () => {
|
|
598
586
|
let input1;
|
|
@@ -647,7 +635,51 @@ export function runPickerTests() {
|
|
|
647
635
|
input1
|
|
648
636
|
);
|
|
649
637
|
});
|
|
650
|
-
|
|
638
|
+
it('traps tab in the menu as a `type="modal"` overlay forward', async () => {
|
|
639
|
+
el.focus();
|
|
640
|
+
await nextFrame();
|
|
641
|
+
expect(document.activeElement, "focuses el").to.equal(el);
|
|
642
|
+
const opened = oneEvent(el, "sp-opened");
|
|
643
|
+
sendKeys({ press: "ArrowDown" });
|
|
644
|
+
await opened;
|
|
645
|
+
expect(el.open, "opened").to.be.true;
|
|
646
|
+
await waitUntil(
|
|
647
|
+
() => isMenuActiveElement(),
|
|
648
|
+
"first item focused"
|
|
649
|
+
);
|
|
650
|
+
const activeElement = document.activeElement;
|
|
651
|
+
if (!isWebKit()) {
|
|
652
|
+
const blured = oneEvent(activeElement, "blur");
|
|
653
|
+
sendKeys({ press: "Tab" });
|
|
654
|
+
await blured;
|
|
655
|
+
expect(el.open, "picker still open").to.be.true;
|
|
656
|
+
expect(document.activeElement === input1).to.be.false;
|
|
657
|
+
expect(document.activeElement === input2).to.be.false;
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
it('traps tab in the menu as a `type="modal"` overlay backwards', async () => {
|
|
661
|
+
el.focus();
|
|
662
|
+
await nextFrame();
|
|
663
|
+
expect(document.activeElement, "focuses el").to.equal(el);
|
|
664
|
+
const opened = oneEvent(el, "sp-opened");
|
|
665
|
+
await sendKeys({ press: "ArrowDown" });
|
|
666
|
+
await opened;
|
|
667
|
+
expect(el.open, "opened").to.be.true;
|
|
668
|
+
await waitUntil(
|
|
669
|
+
() => isMenuActiveElement(),
|
|
670
|
+
"first item focused"
|
|
671
|
+
);
|
|
672
|
+
const activeElement = document.activeElement;
|
|
673
|
+
if (!isWebKit()) {
|
|
674
|
+
const blured = oneEvent(activeElement, "blur");
|
|
675
|
+
sendKeys({ press: "Shift+Tab" });
|
|
676
|
+
await blured;
|
|
677
|
+
expect(el.open, "picker still open").to.be.true;
|
|
678
|
+
expect(document.activeElement === input1).to.be.false;
|
|
679
|
+
expect(document.activeElement === input2).to.be.false;
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
it("can close and immediate tab to the next tab stop", async () => {
|
|
651
683
|
el.focus();
|
|
652
684
|
await nextFrame();
|
|
653
685
|
expect(document.activeElement, "focuses el").to.equal(el);
|
|
@@ -656,7 +688,7 @@ export function runPickerTests() {
|
|
|
656
688
|
await opened;
|
|
657
689
|
expect(el.open, "opened").to.be.true;
|
|
658
690
|
await waitUntil(
|
|
659
|
-
() => isMenuActiveElement(
|
|
691
|
+
() => isMenuActiveElement(),
|
|
660
692
|
"first item focused"
|
|
661
693
|
);
|
|
662
694
|
const closed = oneEvent(el, "sp-closed");
|
|
@@ -673,13 +705,13 @@ export function runPickerTests() {
|
|
|
673
705
|
it("can close and immediate shift+tab to the previous tab stop", async () => {
|
|
674
706
|
el.focus();
|
|
675
707
|
await nextFrame();
|
|
676
|
-
expect(document.activeElement
|
|
708
|
+
expect(document.activeElement, "focuses el").to.equal(el);
|
|
677
709
|
const opened = oneEvent(el, "sp-opened");
|
|
678
710
|
await sendKeys({ press: "ArrowUp" });
|
|
679
711
|
await opened;
|
|
680
712
|
expect(el.open, "opened").to.be.true;
|
|
681
713
|
await waitUntil(
|
|
682
|
-
() => isMenuActiveElement(
|
|
714
|
+
() => isMenuActiveElement(),
|
|
683
715
|
"first item focused"
|
|
684
716
|
);
|
|
685
717
|
const closed = oneEvent(el, "sp-closed");
|
|
@@ -688,7 +720,7 @@ export function runPickerTests() {
|
|
|
688
720
|
expect(el.open).to.be.false;
|
|
689
721
|
expect(document.activeElement === el).to.be.true;
|
|
690
722
|
const focused = oneEvent(input1, "focus");
|
|
691
|
-
sendKeys({ press: "Shift+Tab" });
|
|
723
|
+
await sendKeys({ press: "Shift+Tab" });
|
|
692
724
|
await focused;
|
|
693
725
|
expect(el.open).to.be.false;
|
|
694
726
|
expect(document.activeElement === input1).to.be.true;
|
|
@@ -703,7 +735,8 @@ export function runPickerTests() {
|
|
|
703
735
|
expect(el.open).to.be.false;
|
|
704
736
|
});
|
|
705
737
|
it("scrolls selected into view on open", async () => {
|
|
706
|
-
el.
|
|
738
|
+
await el.generatePopover();
|
|
739
|
+
el.popoverEl.style.height = "40px";
|
|
707
740
|
const firstItem = el.querySelector(
|
|
708
741
|
"sp-menu-item:first-child"
|
|
709
742
|
);
|
|
@@ -713,15 +746,11 @@ export function runPickerTests() {
|
|
|
713
746
|
lastItem.disabled = false;
|
|
714
747
|
el.value = lastItem.value;
|
|
715
748
|
await elementUpdated(el);
|
|
716
|
-
const opened = oneEvent(el, "sp-opened");
|
|
717
749
|
el.open = true;
|
|
718
|
-
await
|
|
719
|
-
await waitUntil(
|
|
720
|
-
() => isMenuActiveElement(el),
|
|
721
|
-
"first item focused"
|
|
722
|
-
);
|
|
750
|
+
await elementUpdated(el);
|
|
751
|
+
await waitUntil(() => isMenuActiveElement(), "first item focused");
|
|
723
752
|
const getParentOffset = (el2) => {
|
|
724
|
-
const parentScroll = el2.
|
|
753
|
+
const parentScroll = el2.parentElement.scrollTop;
|
|
725
754
|
const parentOffset = el2.offsetTop - parentScroll;
|
|
726
755
|
return parentOffset;
|
|
727
756
|
};
|
|
@@ -730,9 +759,7 @@ export function runPickerTests() {
|
|
|
730
759
|
lastItem.dispatchEvent(
|
|
731
760
|
new FocusEvent("focusin", { bubbles: true })
|
|
732
761
|
);
|
|
733
|
-
|
|
734
|
-
press: "ArrowDown"
|
|
735
|
-
});
|
|
762
|
+
lastItem.dispatchEvent(arrowDownEvent());
|
|
736
763
|
await elementUpdated(el);
|
|
737
764
|
await nextFrame();
|
|
738
765
|
expect(getParentOffset(lastItem)).to.be.greaterThan(40);
|
|
@@ -770,8 +797,6 @@ export function runPickerTests() {
|
|
|
770
797
|
beforeEach(async () => {
|
|
771
798
|
el = await groupedFixture();
|
|
772
799
|
await elementUpdated(el);
|
|
773
|
-
await nextFrame();
|
|
774
|
-
await nextFrame();
|
|
775
800
|
});
|
|
776
801
|
it("selects the item with a matching value in a group", async () => {
|
|
777
802
|
const item = el.querySelector("#should-be-selected");
|
|
@@ -809,7 +834,6 @@ export function runPickerTests() {
|
|
|
809
834
|
beforeEach(async () => {
|
|
810
835
|
el = await pickerFixture2();
|
|
811
836
|
await elementUpdated(el);
|
|
812
|
-
await nextFrame();
|
|
813
837
|
});
|
|
814
838
|
afterEach(async () => {
|
|
815
839
|
if (el.open) {
|
|
@@ -895,7 +919,6 @@ export function runPickerTests() {
|
|
|
895
919
|
beforeEach(async () => {
|
|
896
920
|
el = await pickerFixture2();
|
|
897
921
|
await elementUpdated(el);
|
|
898
|
-
await nextFrame();
|
|
899
922
|
});
|
|
900
923
|
afterEach(async () => {
|
|
901
924
|
if (el.open) {
|
|
@@ -912,6 +935,7 @@ export function runPickerTests() {
|
|
|
912
935
|
const opened = oneEvent(el, "sp-opened");
|
|
913
936
|
el.button.click();
|
|
914
937
|
await opened;
|
|
938
|
+
await elementUpdated(el);
|
|
915
939
|
expect(el.open).to.be.true;
|
|
916
940
|
expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
|
|
917
941
|
expect(el.value).to.equal("");
|
|
@@ -931,7 +955,6 @@ export function runPickerTests() {
|
|
|
931
955
|
`);
|
|
932
956
|
const el2 = test.querySelector("sp-picker");
|
|
933
957
|
await elementUpdated(el2);
|
|
934
|
-
await nextFrame();
|
|
935
958
|
let snapshot = await a11ySnapshot({});
|
|
936
959
|
expect(
|
|
937
960
|
findAccessibilityNode(
|
|
@@ -942,9 +965,6 @@ export function runPickerTests() {
|
|
|
942
965
|
).to.not.be.null;
|
|
943
966
|
el2.value = "2";
|
|
944
967
|
await elementUpdated(el2);
|
|
945
|
-
await nextFrame();
|
|
946
|
-
await nextFrame();
|
|
947
|
-
expect(el2.value).to.equal("2");
|
|
948
968
|
snapshot = await a11ySnapshot({});
|
|
949
969
|
expect(
|
|
950
970
|
findAccessibilityNode(
|
|
@@ -954,11 +974,9 @@ export function runPickerTests() {
|
|
|
954
974
|
"`name` is the label text plus the selected item text"
|
|
955
975
|
).to.not.be.null;
|
|
956
976
|
});
|
|
957
|
-
it
|
|
977
|
+
it("toggles between pickers", async () => {
|
|
958
978
|
const el2 = await pickerFixture();
|
|
959
979
|
const el1 = await pickerFixture();
|
|
960
|
-
el1.parentElement.style.float = "left";
|
|
961
|
-
el2.parentElement.style.float = "left";
|
|
962
980
|
el1.id = "away";
|
|
963
981
|
el2.id = "other";
|
|
964
982
|
await Promise.all([elementUpdated(el1), elementUpdated(el2)]);
|
|
@@ -979,8 +997,8 @@ export function runPickerTests() {
|
|
|
979
997
|
closed = oneEvent(el2, "sp-closed");
|
|
980
998
|
el1.click();
|
|
981
999
|
await Promise.all([open, closed]);
|
|
982
|
-
expect(el2.open).to.be.false;
|
|
983
1000
|
expect(el1.open).to.be.true;
|
|
1001
|
+
expect(el2.open).to.be.false;
|
|
984
1002
|
closed = oneEvent(el1, "sp-closed");
|
|
985
1003
|
sendKeys({
|
|
986
1004
|
press: "Escape"
|
|
@@ -989,7 +1007,7 @@ export function runPickerTests() {
|
|
|
989
1007
|
expect(el1.open).to.be.false;
|
|
990
1008
|
});
|
|
991
1009
|
it("displays selected item text by default", async () => {
|
|
992
|
-
var _a, _b, _c, _d
|
|
1010
|
+
var _a, _b, _c, _d;
|
|
993
1011
|
const el2 = await fixture(
|
|
994
1012
|
html`
|
|
995
1013
|
<sp-picker
|
|
@@ -1006,7 +1024,6 @@ export function runPickerTests() {
|
|
|
1006
1024
|
</sp-picker>
|
|
1007
1025
|
`
|
|
1008
1026
|
);
|
|
1009
|
-
await nextFrame();
|
|
1010
1027
|
await elementUpdated(el2);
|
|
1011
1028
|
await waitUntil(
|
|
1012
1029
|
() => {
|
|
@@ -1032,14 +1049,11 @@ export function runPickerTests() {
|
|
|
1032
1049
|
const opened = oneEvent(el2, "sp-opened");
|
|
1033
1050
|
sendKeys({ press: "Enter" });
|
|
1034
1051
|
await opened;
|
|
1052
|
+
await elementUpdated(el2.optionsMenu);
|
|
1035
1053
|
expect(
|
|
1036
|
-
el2 === document.activeElement,
|
|
1054
|
+
el2.optionsMenu === document.activeElement,
|
|
1037
1055
|
`activeElement is ${(_d = document.activeElement) == null ? void 0 : _d.localName}`
|
|
1038
1056
|
).to.be.true;
|
|
1039
|
-
expect(
|
|
1040
|
-
el2.optionsMenu === el2.shadowRoot.activeElement,
|
|
1041
|
-
`activeElement is ${(_e = el2.shadowRoot.activeElement) == null ? void 0 : _e.localName}`
|
|
1042
|
-
).to.be.true;
|
|
1043
1057
|
expect(firstItem.focused, 'firstItem NOT "focused"').to.be.false;
|
|
1044
1058
|
expect(secondItem.focused, 'secondItem "focused"').to.be.true;
|
|
1045
1059
|
expect(el2.optionsMenu.getAttribute("aria-activedescendant")).to.equal(
|
|
@@ -1126,11 +1140,15 @@ export function runPickerTests() {
|
|
|
1126
1140
|
await elementUpdated(el2);
|
|
1127
1141
|
expect(openedSpy.calledOnce).to.be.true;
|
|
1128
1142
|
expect(closedSpy.calledOnce).to.be.false;
|
|
1143
|
+
const openedEvent = openedSpy.args[0][0];
|
|
1144
|
+
expect(openedEvent.detail.interaction).to.equal("modal");
|
|
1129
1145
|
const closed = oneEvent(el2, "sp-closed");
|
|
1130
1146
|
el2.open = false;
|
|
1131
1147
|
await closed;
|
|
1132
1148
|
await elementUpdated(el2);
|
|
1133
1149
|
expect(closedSpy.calledOnce).to.be.true;
|
|
1150
|
+
const closedEvent = closedSpy.args[0][0];
|
|
1151
|
+
expect(closedEvent.detail.interaction).to.equal("modal");
|
|
1134
1152
|
});
|
|
1135
1153
|
}
|
|
1136
1154
|
//# sourceMappingURL=index.js.map
|