@spectrum-web-components/picker 1.2.0-beta.9 → 1.2.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 +176 -30
- package/package.json +16 -16
- package/src/InteractionController.dev.js +7 -1
- package/src/InteractionController.dev.js.map +2 -2
- package/src/InteractionController.js +1 -1
- package/src/InteractionController.js.map +2 -2
- package/src/MobileController.dev.js +4 -1
- package/src/MobileController.dev.js.map +2 -2
- package/src/MobileController.js +1 -1
- package/src/MobileController.js.map +2 -2
- package/src/Picker.d.ts +35 -5
- package/src/Picker.dev.js +143 -67
- package/src/Picker.dev.js.map +2 -2
- package/src/Picker.js +17 -21
- package/src/Picker.js.map +3 -3
- package/test/index.js +318 -298
- package/test/index.js.map +3 -3
- package/test/picker-reparenting.test.js +12 -3
- package/test/picker-reparenting.test.js.map +2 -2
package/test/index.js
CHANGED
|
@@ -9,21 +9,33 @@ import {
|
|
|
9
9
|
oneEvent,
|
|
10
10
|
waitUntil
|
|
11
11
|
} from "@open-wc/testing";
|
|
12
|
+
import "@spectrum-web-components/field-label/sp-field-label.js";
|
|
13
|
+
import "@spectrum-web-components/menu/sp-menu-group.js";
|
|
14
|
+
import "@spectrum-web-components/menu/sp-menu-item.js";
|
|
15
|
+
import "@spectrum-web-components/menu/sp-menu.js";
|
|
16
|
+
import "@spectrum-web-components/picker/sp-picker.js";
|
|
17
|
+
import { SAFARI_FOCUS_RING_CLASS } from "@spectrum-web-components/picker/src/InteractionController.js";
|
|
18
|
+
import { isWebKit } from "@spectrum-web-components/shared";
|
|
12
19
|
import "@spectrum-web-components/shared/src/focus-visible.js";
|
|
20
|
+
import "@spectrum-web-components/theme/src/themes.js";
|
|
21
|
+
import {
|
|
22
|
+
a11ySnapshot,
|
|
23
|
+
findAccessibilityNode,
|
|
24
|
+
sendKeys,
|
|
25
|
+
setViewport
|
|
26
|
+
} from "@web/test-runner-commands";
|
|
13
27
|
import { spy, stub } from "sinon";
|
|
28
|
+
import { sendMouse } from "../../../test/plugins/browser.js";
|
|
14
29
|
import {
|
|
15
30
|
arrowDownEvent,
|
|
16
31
|
arrowRightEvent,
|
|
17
32
|
arrowUpEvent,
|
|
33
|
+
ignoreResizeObserverLoopError,
|
|
34
|
+
fixture as styledFixture,
|
|
18
35
|
testForLitDevWarnings,
|
|
19
36
|
tEvent
|
|
20
37
|
} from "../../../test/testing-helpers.js";
|
|
21
|
-
import {
|
|
22
|
-
a11ySnapshot,
|
|
23
|
-
findAccessibilityNode,
|
|
24
|
-
sendKeys,
|
|
25
|
-
setViewport
|
|
26
|
-
} from "@web/test-runner-commands";
|
|
38
|
+
import { M as pending } from "../stories/picker-pending.stories.js";
|
|
27
39
|
import {
|
|
28
40
|
Default,
|
|
29
41
|
disabled,
|
|
@@ -33,25 +45,12 @@ import {
|
|
|
33
45
|
slottedLabel,
|
|
34
46
|
tooltip
|
|
35
47
|
} from "../stories/picker.stories.js";
|
|
36
|
-
import { M as pending } from "../stories/picker-pending.stories.js";
|
|
37
|
-
import { sendMouse } from "../../../test/plugins/browser.js";
|
|
38
|
-
import {
|
|
39
|
-
ignoreResizeObserverLoopError,
|
|
40
|
-
fixture as styledFixture
|
|
41
|
-
} from "../../../test/testing-helpers.js";
|
|
42
|
-
import "@spectrum-web-components/picker/sp-picker.js";
|
|
43
|
-
import "@spectrum-web-components/field-label/sp-field-label.js";
|
|
44
|
-
import "@spectrum-web-components/menu/sp-menu.js";
|
|
45
|
-
import "@spectrum-web-components/menu/sp-menu-group.js";
|
|
46
|
-
import "@spectrum-web-components/menu/sp-menu-item.js";
|
|
47
|
-
import "@spectrum-web-components/theme/src/themes.js";
|
|
48
|
-
import { isWebKit } from "@spectrum-web-components/shared";
|
|
49
|
-
import { SAFARI_FOCUS_RING_CLASS } from "@spectrum-web-components/picker/src/InteractionController.js";
|
|
50
48
|
ignoreResizeObserverLoopError(before, after);
|
|
51
49
|
const isMenuActiveElement = function(el) {
|
|
52
50
|
var _a;
|
|
53
|
-
return ((_a =
|
|
51
|
+
return ((_a = document.activeElement) == null ? void 0 : _a.tagName) === "SP-MENU-ITEM" && el.contains(document.activeElement);
|
|
54
52
|
};
|
|
53
|
+
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
55
54
|
export function runPickerTests() {
|
|
56
55
|
let el;
|
|
57
56
|
const pickerFixture = async () => {
|
|
@@ -195,7 +194,7 @@ export function runPickerTests() {
|
|
|
195
194
|
const opened = oneEvent(el, "sp-opened");
|
|
196
195
|
el.open = true;
|
|
197
196
|
await opened;
|
|
198
|
-
expect(el.open).to.be.true;
|
|
197
|
+
expect(el.open, "open?").to.be.true;
|
|
199
198
|
const accessibleCloseButton = el.shadowRoot.querySelector(
|
|
200
199
|
".visually-hidden button"
|
|
201
200
|
);
|
|
@@ -203,11 +202,11 @@ export function runPickerTests() {
|
|
|
203
202
|
"aria-label",
|
|
204
203
|
"Dismiss"
|
|
205
204
|
);
|
|
206
|
-
const
|
|
205
|
+
const closed2 = oneEvent(el, "sp-closed");
|
|
207
206
|
accessibleCloseButton.click();
|
|
208
|
-
await
|
|
207
|
+
await closed2;
|
|
209
208
|
await elementUpdated(el);
|
|
210
|
-
expect(el.open).to.be.false;
|
|
209
|
+
expect(el.open, "open?").to.be.false;
|
|
211
210
|
expect(el.shadowRoot.activeElement).to.equal(el.button);
|
|
212
211
|
expect(document.activeElement).to.eq(el);
|
|
213
212
|
});
|
|
@@ -352,25 +351,6 @@ export function runPickerTests() {
|
|
|
352
351
|
"`name` is the selected item text plus the label text"
|
|
353
352
|
).to.not.be.null;
|
|
354
353
|
});
|
|
355
|
-
it("manages `aria-activedescendant`", async () => {
|
|
356
|
-
const firstItem = el.querySelector("sp-menu-item:nth-child(1)");
|
|
357
|
-
const secondItem = el.querySelector("sp-menu-item:nth-child(2)");
|
|
358
|
-
const opened = oneEvent(el, "sp-opened");
|
|
359
|
-
el.open = true;
|
|
360
|
-
await opened;
|
|
361
|
-
expect(
|
|
362
|
-
el.optionsMenu.getAttribute(
|
|
363
|
-
"aria-activedescendant"
|
|
364
|
-
)
|
|
365
|
-
).to.equal(firstItem == null ? void 0 : firstItem.id);
|
|
366
|
-
await sendKeys({ press: "ArrowDown" });
|
|
367
|
-
await elementUpdated(el);
|
|
368
|
-
expect(
|
|
369
|
-
el.optionsMenu.getAttribute(
|
|
370
|
-
"aria-activedescendant"
|
|
371
|
-
)
|
|
372
|
-
).to.equal(secondItem == null ? void 0 : secondItem.id);
|
|
373
|
-
});
|
|
374
354
|
it("renders invalid accessibly", async () => {
|
|
375
355
|
el.invalid = true;
|
|
376
356
|
await elementUpdated(el);
|
|
@@ -383,58 +363,61 @@ export function runPickerTests() {
|
|
|
383
363
|
await expect(el).to.be.accessible();
|
|
384
364
|
});
|
|
385
365
|
it("opens with visible focus on a menu item on `DownArrow`", async () => {
|
|
386
|
-
var _a, _b;
|
|
387
366
|
const firstItem = el.querySelector("sp-menu-item");
|
|
388
|
-
|
|
389
|
-
|
|
367
|
+
const opened = oneEvent(el, "sp-opened");
|
|
368
|
+
const closed2 = oneEvent(el, "sp-closed");
|
|
369
|
+
expect(
|
|
370
|
+
firstItem.focused,
|
|
371
|
+
"first item should not be visually focused before opening"
|
|
372
|
+
).to.be.false;
|
|
390
373
|
el.focus();
|
|
391
374
|
await elementUpdated(el);
|
|
392
|
-
const opened = oneEvent(el, "sp-opened");
|
|
393
|
-
await sendKeys({ press: "ArrowRight" });
|
|
394
|
-
await sendKeys({ press: "ArrowLeft" });
|
|
395
375
|
await sendKeys({ press: "ArrowDown" });
|
|
396
376
|
await opened;
|
|
397
|
-
expect(el.open).to.be.true;
|
|
398
|
-
expect(
|
|
399
|
-
|
|
377
|
+
expect(el.open, "picker should be open").to.be.true;
|
|
378
|
+
expect(
|
|
379
|
+
firstItem.focused,
|
|
380
|
+
"first item should be visually focused after opening"
|
|
381
|
+
).to.be.true;
|
|
400
382
|
await sendKeys({
|
|
401
383
|
press: "Escape"
|
|
402
384
|
});
|
|
403
|
-
await
|
|
404
|
-
expect(el.open).to.be.false;
|
|
405
|
-
expect(
|
|
406
|
-
|
|
407
|
-
`focused ${(_a = document.activeElement) == null ? void 0 : _a.localName} instead of back on Picker`
|
|
408
|
-
).to.be.true;
|
|
409
|
-
expect(
|
|
410
|
-
el.shadowRoot.activeElement === el.button,
|
|
411
|
-
`focused ${(_b = el.shadowRoot.activeElement) == null ? void 0 : _b.localName} instead of back on button`
|
|
412
|
-
).to.be.true;
|
|
385
|
+
await closed2;
|
|
386
|
+
expect(el.open, "picker should be closed").to.be.false;
|
|
387
|
+
expect(document.activeElement).to.equal(el);
|
|
388
|
+
expect(el.shadowRoot.activeElement).to.equal(el.button);
|
|
413
389
|
await waitUntil(
|
|
414
390
|
() => !firstItem.focused,
|
|
415
391
|
"finally, not visually focused"
|
|
416
392
|
);
|
|
393
|
+
expect(
|
|
394
|
+
firstItem.focused,
|
|
395
|
+
"first item should not be visually focused after closing"
|
|
396
|
+
).to.be.false;
|
|
417
397
|
});
|
|
418
398
|
it("opens with visible focus on a menu item on `Space`", async function() {
|
|
419
399
|
var _a, _b;
|
|
420
400
|
const firstItem = el.querySelector("sp-menu-item");
|
|
421
|
-
|
|
422
|
-
|
|
401
|
+
const opened = oneEvent(el, "sp-opened");
|
|
402
|
+
const closed2 = oneEvent(el, "sp-closed");
|
|
403
|
+
expect(
|
|
404
|
+
firstItem.focused,
|
|
405
|
+
"should not be visually focused before opening"
|
|
406
|
+
).to.be.false;
|
|
423
407
|
el.focus();
|
|
424
408
|
await elementUpdated(el);
|
|
425
|
-
const opened = oneEvent(el, "sp-opened");
|
|
426
|
-
await sendKeys({ press: "ArrowRight" });
|
|
427
|
-
await sendKeys({ press: "ArrowLeft" });
|
|
428
409
|
await sendKeys({ press: "Space" });
|
|
429
410
|
await opened;
|
|
430
|
-
expect(el.open).to.be.true;
|
|
431
|
-
expect(
|
|
432
|
-
|
|
411
|
+
expect(el.open, "open?").to.be.true;
|
|
412
|
+
expect(
|
|
413
|
+
firstItem.focused,
|
|
414
|
+
"should be visually focused after opening"
|
|
415
|
+
).to.be.true;
|
|
433
416
|
await sendKeys({
|
|
434
417
|
press: "Escape"
|
|
435
418
|
});
|
|
436
|
-
await
|
|
437
|
-
expect(el.open).to.be.false;
|
|
419
|
+
await closed2;
|
|
420
|
+
expect(el.open, "picker should be closed").to.be.false;
|
|
438
421
|
expect(
|
|
439
422
|
document.activeElement === el,
|
|
440
423
|
`focused ${(_a = document.activeElement) == null ? void 0 : _a.localName} instead of back on Picker`
|
|
@@ -447,8 +430,12 @@ export function runPickerTests() {
|
|
|
447
430
|
() => !firstItem.focused,
|
|
448
431
|
"finally, not visually focused"
|
|
449
432
|
);
|
|
433
|
+
expect(
|
|
434
|
+
firstItem.focused,
|
|
435
|
+
"first item should not be visually focused after closing"
|
|
436
|
+
).to.be.false;
|
|
450
437
|
});
|
|
451
|
-
it("opens, on click,
|
|
438
|
+
it("opens, on click, with visible focus on a menu item", async () => {
|
|
452
439
|
await nextFrame();
|
|
453
440
|
await nextFrame();
|
|
454
441
|
const firstItem = el.querySelector("sp-menu-item");
|
|
@@ -467,8 +454,8 @@ export function runPickerTests() {
|
|
|
467
454
|
]
|
|
468
455
|
});
|
|
469
456
|
await opened;
|
|
470
|
-
expect(el.open).to.be.true;
|
|
471
|
-
expect(firstItem.focused, "
|
|
457
|
+
expect(el.open, "open?").to.be.true;
|
|
458
|
+
expect(firstItem.focused, "firstItem focused?").to.be.true;
|
|
472
459
|
});
|
|
473
460
|
it("opens and selects in a single pointer button interaction", async () => {
|
|
474
461
|
await nextFrame();
|
|
@@ -495,7 +482,7 @@ export function runPickerTests() {
|
|
|
495
482
|
});
|
|
496
483
|
await opened;
|
|
497
484
|
const thirdItemRect = thirdItem.getBoundingClientRect();
|
|
498
|
-
const
|
|
485
|
+
const closed2 = oneEvent(el, "sp-closed");
|
|
499
486
|
await sendMouse({
|
|
500
487
|
steps: [
|
|
501
488
|
{
|
|
@@ -510,14 +497,12 @@ export function runPickerTests() {
|
|
|
510
497
|
}
|
|
511
498
|
]
|
|
512
499
|
});
|
|
513
|
-
await
|
|
514
|
-
expect(el.open).to.be.false;
|
|
500
|
+
await closed2;
|
|
501
|
+
expect(el.open, "open?").to.be.false;
|
|
515
502
|
expect(el.value).to.equal(thirdItem.value);
|
|
516
503
|
});
|
|
517
504
|
it("opens/closes multiple times", async () => {
|
|
518
|
-
|
|
519
|
-
await nextFrame();
|
|
520
|
-
expect(el.open).to.be.false;
|
|
505
|
+
expect(el.open, "open?").to.be.false;
|
|
521
506
|
const boundingRect = el.button.getBoundingClientRect();
|
|
522
507
|
let opened = oneEvent(el, "sp-opened");
|
|
523
508
|
sendMouse({
|
|
@@ -532,8 +517,8 @@ export function runPickerTests() {
|
|
|
532
517
|
]
|
|
533
518
|
});
|
|
534
519
|
await opened;
|
|
535
|
-
expect(el.open).to.be.true;
|
|
536
|
-
let
|
|
520
|
+
expect(el.open, "open?").to.be.true;
|
|
521
|
+
let closed2 = oneEvent(el, "sp-closed");
|
|
537
522
|
sendMouse({
|
|
538
523
|
steps: [
|
|
539
524
|
{
|
|
@@ -545,8 +530,8 @@ export function runPickerTests() {
|
|
|
545
530
|
}
|
|
546
531
|
]
|
|
547
532
|
});
|
|
548
|
-
await
|
|
549
|
-
expect(el.open).to.be.false;
|
|
533
|
+
await closed2;
|
|
534
|
+
expect(el.open, "open?").to.be.false;
|
|
550
535
|
opened = oneEvent(el, "sp-opened");
|
|
551
536
|
sendMouse({
|
|
552
537
|
steps: [
|
|
@@ -560,8 +545,8 @@ export function runPickerTests() {
|
|
|
560
545
|
]
|
|
561
546
|
});
|
|
562
547
|
await opened;
|
|
563
|
-
expect(el.open).to.be.true;
|
|
564
|
-
|
|
548
|
+
expect(el.open, "open?").to.be.true;
|
|
549
|
+
closed2 = oneEvent(el, "sp-closed");
|
|
565
550
|
sendMouse({
|
|
566
551
|
steps: [
|
|
567
552
|
{
|
|
@@ -573,32 +558,32 @@ export function runPickerTests() {
|
|
|
573
558
|
}
|
|
574
559
|
]
|
|
575
560
|
});
|
|
576
|
-
await
|
|
577
|
-
expect(el.open).to.be.false;
|
|
561
|
+
await closed2;
|
|
562
|
+
expect(el.open, "open?").to.be.false;
|
|
578
563
|
});
|
|
579
564
|
it("closes when becoming disabled", async () => {
|
|
580
|
-
expect(el.open).to.be.false;
|
|
565
|
+
expect(el.open, "open before click?").to.be.false;
|
|
581
566
|
el.click();
|
|
582
567
|
await elementUpdated(el);
|
|
583
|
-
expect(el.open).to.be.true;
|
|
568
|
+
expect(el.open, "open after click?").to.be.true;
|
|
584
569
|
el.disabled = true;
|
|
585
|
-
await
|
|
586
|
-
expect(el.open).to.be.false;
|
|
570
|
+
await closed;
|
|
571
|
+
expect(el.open, "open after disabled?").to.be.false;
|
|
587
572
|
});
|
|
588
573
|
it("closes when clicking away", async () => {
|
|
589
574
|
el.id = "closing";
|
|
590
575
|
const other = document.createElement("div");
|
|
591
576
|
document.body.append(other);
|
|
592
577
|
await elementUpdated(el);
|
|
593
|
-
expect(el.open).to.be.false;
|
|
578
|
+
expect(el.open, "open?").to.be.false;
|
|
594
579
|
const opened = oneEvent(el, "sp-opened");
|
|
595
580
|
el.click();
|
|
596
581
|
await opened;
|
|
597
582
|
await elementUpdated(el);
|
|
598
|
-
expect(el.open).to.be.true;
|
|
599
|
-
const
|
|
583
|
+
expect(el.open, "open?").to.be.true;
|
|
584
|
+
const closed2 = oneEvent(el, "sp-closed");
|
|
600
585
|
other.click();
|
|
601
|
-
|
|
586
|
+
closed2;
|
|
602
587
|
await elementUpdated(el);
|
|
603
588
|
other.remove();
|
|
604
589
|
});
|
|
@@ -610,13 +595,13 @@ export function runPickerTests() {
|
|
|
610
595
|
const opened = oneEvent(el, "sp-opened");
|
|
611
596
|
el.click();
|
|
612
597
|
await opened;
|
|
613
|
-
expect(el.open).to.be.true;
|
|
598
|
+
expect(el.open, "open?").to.be.true;
|
|
614
599
|
expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
|
|
615
600
|
expect(el.value).to.equal("");
|
|
616
|
-
const
|
|
601
|
+
const closed2 = oneEvent(el, "sp-closed");
|
|
617
602
|
secondItem.click();
|
|
618
|
-
await
|
|
619
|
-
expect(el.open).to.be.false;
|
|
603
|
+
await closed2;
|
|
604
|
+
expect(el.open, "open?").to.be.false;
|
|
620
605
|
expect((_b = el.selectedItem) == null ? void 0 : _b.itemText).to.equal("Select Inverse");
|
|
621
606
|
expect(el.value).to.equal("option-2");
|
|
622
607
|
});
|
|
@@ -631,25 +616,25 @@ export function runPickerTests() {
|
|
|
631
616
|
let opened = oneEvent(el, "sp-opened");
|
|
632
617
|
el.click();
|
|
633
618
|
await opened;
|
|
634
|
-
expect(el.open).to.be.true;
|
|
619
|
+
expect(el.open, "open?").to.be.true;
|
|
635
620
|
expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
|
|
636
621
|
expect(el.value).to.equal("");
|
|
637
|
-
let
|
|
622
|
+
let closed2 = oneEvent(el, "sp-closed");
|
|
638
623
|
secondItem.click();
|
|
639
|
-
await
|
|
640
|
-
expect(el.open).to.be.false;
|
|
624
|
+
await closed2;
|
|
625
|
+
expect(el.open, "open?").to.be.false;
|
|
641
626
|
expect((_b = el.selectedItem) == null ? void 0 : _b.itemText).to.equal("Select Inverse");
|
|
642
627
|
expect(el.value).to.equal("option-2");
|
|
643
628
|
opened = oneEvent(el, "sp-opened");
|
|
644
629
|
el.click();
|
|
645
630
|
await opened;
|
|
646
|
-
expect(el.open).to.be.true;
|
|
631
|
+
expect(el.open, "open?").to.be.true;
|
|
647
632
|
expect((_c = el.selectedItem) == null ? void 0 : _c.itemText).to.equal("Select Inverse");
|
|
648
633
|
expect(el.value).to.equal("option-2");
|
|
649
|
-
|
|
634
|
+
closed2 = oneEvent(el, "sp-closed");
|
|
650
635
|
firstItem.click();
|
|
651
|
-
await
|
|
652
|
-
expect(el.open).to.be.false;
|
|
636
|
+
await closed2;
|
|
637
|
+
expect(el.open, "open?").to.be.false;
|
|
653
638
|
expect((_d = el.selectedItem) == null ? void 0 : _d.itemText).to.equal("Deselect");
|
|
654
639
|
expect(el.value).to.equal("Deselect");
|
|
655
640
|
});
|
|
@@ -665,9 +650,9 @@ export function runPickerTests() {
|
|
|
665
650
|
const opened = oneEvent(el, "sp-opened");
|
|
666
651
|
el.open = true;
|
|
667
652
|
await opened;
|
|
668
|
-
const
|
|
653
|
+
const closed2 = oneEvent(el, "sp-closed");
|
|
669
654
|
secondItem.click();
|
|
670
|
-
await
|
|
655
|
+
await closed2;
|
|
671
656
|
expect(el.value).to.equal(secondItem.value);
|
|
672
657
|
expect(changeSpy.calledOnce).to.be.true;
|
|
673
658
|
});
|
|
@@ -680,7 +665,7 @@ export function runPickerTests() {
|
|
|
680
665
|
const opened = oneEvent(el, "sp-opened");
|
|
681
666
|
el.click();
|
|
682
667
|
await opened;
|
|
683
|
-
expect(el.open).to.be.true;
|
|
668
|
+
expect(el.open, "open?").to.be.true;
|
|
684
669
|
expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
|
|
685
670
|
expect(el.value).to.equal("");
|
|
686
671
|
expect(secondItem.selected).to.be.false;
|
|
@@ -696,9 +681,9 @@ export function runPickerTests() {
|
|
|
696
681
|
preventChangeSpy.callCount.toString()
|
|
697
682
|
).to.be.true;
|
|
698
683
|
expect(secondItem.selected, "selection prevented").to.be.false;
|
|
699
|
-
expect(el.open).to.be.true;
|
|
684
|
+
expect(el.open, "open?").to.be.true;
|
|
700
685
|
});
|
|
701
|
-
it("
|
|
686
|
+
it("should return focus after click", async () => {
|
|
702
687
|
var _a;
|
|
703
688
|
const input = document.createElement("input");
|
|
704
689
|
document.body.append(input);
|
|
@@ -710,24 +695,49 @@ export function runPickerTests() {
|
|
|
710
695
|
el.click();
|
|
711
696
|
await opened;
|
|
712
697
|
await elementUpdated(el);
|
|
713
|
-
expect(el.open).to.be.true;
|
|
698
|
+
expect(el.open, "open?").to.be.true;
|
|
699
|
+
expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
|
|
700
|
+
expect(el.value).to.equal("");
|
|
701
|
+
expect(secondItem.selected).to.be.false;
|
|
702
|
+
secondItem.click();
|
|
703
|
+
await waitUntil(
|
|
704
|
+
() => document.activeElement === el,
|
|
705
|
+
"focused",
|
|
706
|
+
{ timeout: 300 }
|
|
707
|
+
);
|
|
708
|
+
expect(el.open, "open?").to.be.false;
|
|
709
|
+
expect(el.value, "value changed").to.equal("option-2");
|
|
710
|
+
expect(secondItem.selected, "selected changed").to.be.true;
|
|
711
|
+
input.remove();
|
|
712
|
+
});
|
|
713
|
+
it("should throw focus after `change`", async () => {
|
|
714
|
+
var _a;
|
|
715
|
+
const input = document.createElement("input");
|
|
716
|
+
document.body.append(input);
|
|
717
|
+
await elementUpdated(el);
|
|
718
|
+
const secondItem = el.querySelector(
|
|
719
|
+
"sp-menu-item:nth-of-type(2)"
|
|
720
|
+
);
|
|
721
|
+
const opened = oneEvent(el, "sp-opened");
|
|
722
|
+
el.click();
|
|
723
|
+
await opened;
|
|
724
|
+
await elementUpdated(el);
|
|
725
|
+
expect(el.open, "open?").to.be.true;
|
|
714
726
|
expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
|
|
715
727
|
expect(el.value).to.equal("");
|
|
716
728
|
expect(secondItem.selected).to.be.false;
|
|
717
729
|
el.addEventListener("change", () => {
|
|
718
730
|
input.focus();
|
|
719
731
|
});
|
|
720
|
-
const closed = oneEvent(el, "sp-closed");
|
|
721
732
|
secondItem.click();
|
|
722
|
-
await closed;
|
|
723
|
-
await elementUpdated(el);
|
|
724
|
-
expect(el.open).to.be.false;
|
|
725
|
-
expect(el.value, "value changed").to.equal("option-2");
|
|
726
|
-
expect(secondItem.selected, "selected changed").to.be.true;
|
|
727
733
|
await waitUntil(
|
|
728
734
|
() => document.activeElement === input,
|
|
729
|
-
"focus throw"
|
|
735
|
+
"focus throw",
|
|
736
|
+
{ timeout: 300 }
|
|
730
737
|
);
|
|
738
|
+
expect(el.open, "open?").to.be.false;
|
|
739
|
+
expect(el.value, "value changed").to.equal("option-2");
|
|
740
|
+
expect(secondItem.selected, "selected changed").to.be.true;
|
|
731
741
|
input.remove();
|
|
732
742
|
});
|
|
733
743
|
it("opens on ArrowUp", async () => {
|
|
@@ -743,12 +753,12 @@ export function runPickerTests() {
|
|
|
743
753
|
await elementUpdated(el);
|
|
744
754
|
expect(el.open, "open by ArrowUp").to.be.true;
|
|
745
755
|
await opened;
|
|
746
|
-
const
|
|
756
|
+
const closed2 = oneEvent(el, "sp-closed");
|
|
747
757
|
sendKeys({
|
|
748
758
|
press: "Escape"
|
|
749
759
|
});
|
|
750
|
-
await
|
|
751
|
-
expect(el.open).to.be.false;
|
|
760
|
+
await closed2;
|
|
761
|
+
expect(el.open, "should be closed after escape key is pressed").to.be.false;
|
|
752
762
|
});
|
|
753
763
|
it("opens on ArrowDown", async () => {
|
|
754
764
|
var _a, _b;
|
|
@@ -765,10 +775,10 @@ export function runPickerTests() {
|
|
|
765
775
|
expect(el.open, "open by ArrowDown").to.be.true;
|
|
766
776
|
expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
|
|
767
777
|
expect(el.value).to.equal("");
|
|
768
|
-
const
|
|
778
|
+
const closed2 = oneEvent(el, "sp-closed");
|
|
769
779
|
firstItem.click();
|
|
770
|
-
await
|
|
771
|
-
expect(el.open).to.be.false;
|
|
780
|
+
await closed2;
|
|
781
|
+
expect(el.open, "open?").to.be.false;
|
|
772
782
|
expect((_b = el.selectedItem) == null ? void 0 : _b.itemText).to.equal("Deselect");
|
|
773
783
|
expect(el.value).to.equal("Deselect");
|
|
774
784
|
});
|
|
@@ -787,19 +797,25 @@ export function runPickerTests() {
|
|
|
787
797
|
press: "ArrowLeft"
|
|
788
798
|
});
|
|
789
799
|
await elementUpdated(el);
|
|
790
|
-
expect(
|
|
800
|
+
expect(
|
|
801
|
+
selectionSpy.callCount,
|
|
802
|
+
`selectionSpy.callCount: ${selectionSpy.callCount}`
|
|
803
|
+
).to.equal(1);
|
|
791
804
|
expect(selectionSpy.calledWith("Deselected"));
|
|
792
805
|
await sendKeys({
|
|
793
806
|
press: "ArrowLeft"
|
|
794
807
|
});
|
|
795
808
|
await elementUpdated(el);
|
|
796
|
-
expect(
|
|
809
|
+
expect(
|
|
810
|
+
selectionSpy.callCount,
|
|
811
|
+
`selectionSpy.callCount: ${selectionSpy.callCount}`
|
|
812
|
+
).to.equal(1);
|
|
797
813
|
await sendKeys({
|
|
798
814
|
press: "ArrowRight"
|
|
799
815
|
});
|
|
800
816
|
await nextFrame();
|
|
801
817
|
await nextFrame();
|
|
802
|
-
expect(selectionSpy.calledWith("option-2"));
|
|
818
|
+
expect(selectionSpy.calledWith("option-2"), "option-2");
|
|
803
819
|
await sendKeys({
|
|
804
820
|
press: "ArrowRight"
|
|
805
821
|
});
|
|
@@ -820,9 +836,18 @@ export function runPickerTests() {
|
|
|
820
836
|
});
|
|
821
837
|
await nextFrame();
|
|
822
838
|
await nextFrame();
|
|
823
|
-
expect(
|
|
824
|
-
|
|
825
|
-
|
|
839
|
+
expect(
|
|
840
|
+
selectionSpy.calledWith("Save Selection"),
|
|
841
|
+
'selectionSpy.calledWith("Save Selection")'
|
|
842
|
+
);
|
|
843
|
+
expect(
|
|
844
|
+
selectionSpy.calledWith("Make Work Path"),
|
|
845
|
+
'selectionSpy.calledWith("Make Work Path")'
|
|
846
|
+
).to.be.false;
|
|
847
|
+
expect(
|
|
848
|
+
selectionSpy.callCount,
|
|
849
|
+
`selectionSpy.callCount: ${selectionSpy.callCount}`
|
|
850
|
+
).to.equal(5);
|
|
826
851
|
});
|
|
827
852
|
it("quick selects first item on ArrowRight when no value", async () => {
|
|
828
853
|
await nextFrame();
|
|
@@ -850,10 +875,12 @@ export function runPickerTests() {
|
|
|
850
875
|
const input = document.createElement("input");
|
|
851
876
|
el.insertAdjacentElement("afterend", input);
|
|
852
877
|
el.focus();
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
878
|
+
if (!isSafari) {
|
|
879
|
+
await sendKeys({ press: "Tab" });
|
|
880
|
+
expect(document.activeElement).to.equal(input);
|
|
881
|
+
await sendKeys({ press: "Shift+Tab" });
|
|
882
|
+
}
|
|
883
|
+
expect(document.activeElement).to.equal(el);
|
|
857
884
|
const opened = oneEvent(el, "sp-opened");
|
|
858
885
|
sendKeys({ press: "Enter" });
|
|
859
886
|
await opened;
|
|
@@ -864,12 +891,12 @@ export function runPickerTests() {
|
|
|
864
891
|
);
|
|
865
892
|
await sendKeys({ press: "ArrowDown" });
|
|
866
893
|
await sendKeys({ press: "ArrowDown" });
|
|
867
|
-
expect(thirdItem.focused).to.be.true;
|
|
868
|
-
const
|
|
894
|
+
expect(thirdItem.focused, "thirdItem focused?").to.be.true;
|
|
895
|
+
const closed2 = oneEvent(el, "sp-closed");
|
|
869
896
|
button.focus();
|
|
870
|
-
await
|
|
897
|
+
await closed2;
|
|
871
898
|
expect(isMenuActiveElement(el)).to.be.false;
|
|
872
|
-
expect(el.open).to.be.false;
|
|
899
|
+
expect(el.open, "open?").to.be.false;
|
|
873
900
|
});
|
|
874
901
|
it("does not listen to streaming `Enter` keydown", async () => {
|
|
875
902
|
const openSpy = spy();
|
|
@@ -883,10 +910,12 @@ export function runPickerTests() {
|
|
|
883
910
|
const input = document.createElement("input");
|
|
884
911
|
el.insertAdjacentElement("afterend", input);
|
|
885
912
|
el.focus();
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
913
|
+
if (!isSafari) {
|
|
914
|
+
await sendKeys({ press: "Tab" });
|
|
915
|
+
expect(document.activeElement).to.equal(input);
|
|
916
|
+
await sendKeys({ press: "Shift+Tab" });
|
|
917
|
+
}
|
|
918
|
+
expect(document.activeElement).to.equal(el);
|
|
890
919
|
const opened = oneEvent(el, "sp-opened");
|
|
891
920
|
sendKeys({ down: "Enter" });
|
|
892
921
|
await opened;
|
|
@@ -899,28 +928,28 @@ export function runPickerTests() {
|
|
|
899
928
|
);
|
|
900
929
|
await sendKeys({ press: "ArrowDown" });
|
|
901
930
|
await sendKeys({ press: "ArrowDown" });
|
|
902
|
-
expect(thirdItem.focused).to.be.true;
|
|
903
|
-
const
|
|
931
|
+
expect(thirdItem.focused, "thirdItem focused?").to.be.true;
|
|
932
|
+
const closed2 = oneEvent(el, "sp-closed");
|
|
904
933
|
sendKeys({ down: "Enter" });
|
|
905
|
-
await
|
|
934
|
+
await closed2;
|
|
906
935
|
await aTimeout(300);
|
|
907
936
|
expect(el.value).to.equal(thirdItem.value);
|
|
908
937
|
expect(openSpy.callCount).to.equal(1);
|
|
909
938
|
expect(closedSpy.callCount).to.equal(1);
|
|
910
939
|
await sendKeys({ up: "Enter" });
|
|
911
940
|
});
|
|
912
|
-
it("allows
|
|
941
|
+
it("allows tabbing to close", async () => {
|
|
913
942
|
const input = document.createElement("input");
|
|
914
943
|
el.insertAdjacentElement("afterend", input);
|
|
915
944
|
const opened = oneEvent(el, "sp-opened");
|
|
916
945
|
el.open = true;
|
|
917
946
|
await opened;
|
|
918
947
|
await nextFrame();
|
|
919
|
-
expect(el.open).to.be.true;
|
|
948
|
+
expect(el.open, "open?").to.be.true;
|
|
920
949
|
el.focus();
|
|
921
|
-
const
|
|
950
|
+
const closed2 = oneEvent(el, "sp-closed");
|
|
922
951
|
sendKeys({ press: "Tab" });
|
|
923
|
-
await
|
|
952
|
+
await closed2;
|
|
924
953
|
expect(el.open, "closes").to.be.false;
|
|
925
954
|
});
|
|
926
955
|
describe("tab order", () => {
|
|
@@ -943,11 +972,17 @@ export function runPickerTests() {
|
|
|
943
972
|
input2.remove();
|
|
944
973
|
});
|
|
945
974
|
it("tabs forward through the element", async () => {
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
975
|
+
let focused;
|
|
976
|
+
if (!isSafari) {
|
|
977
|
+
input1.focus();
|
|
978
|
+
await nextFrame();
|
|
979
|
+
expect(document.activeElement === input1, "focuses input 1").to.true;
|
|
980
|
+
focused = oneEvent(el, "focus");
|
|
981
|
+
await sendKeys({ press: "Tab" });
|
|
982
|
+
} else {
|
|
983
|
+
focused = oneEvent(el, "focus");
|
|
984
|
+
el.focus();
|
|
985
|
+
}
|
|
951
986
|
await focused;
|
|
952
987
|
expect(el.focused, "focused").to.be.true;
|
|
953
988
|
expect(el.open, "closed").to.be.false;
|
|
@@ -964,40 +999,35 @@ export function runPickerTests() {
|
|
|
964
999
|
input2
|
|
965
1000
|
);
|
|
966
1001
|
let focused = oneEvent(el, "focus");
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
1002
|
+
if (!isSafari) {
|
|
1003
|
+
await sendKeys({ press: "Shift+Tab" });
|
|
1004
|
+
await focused;
|
|
1005
|
+
expect(el.focused, "focused").to.be.true;
|
|
1006
|
+
expect(el.open, "closed").to.be.false;
|
|
1007
|
+
expect(document.activeElement, "focuses el").to.equal(el);
|
|
1008
|
+
} else {
|
|
1009
|
+
el.focus();
|
|
1010
|
+
}
|
|
972
1011
|
focused = oneEvent(input1, "focus");
|
|
973
1012
|
await sendKeys({ press: "Shift+Tab" });
|
|
974
1013
|
await focused;
|
|
975
|
-
expect(document.activeElement
|
|
976
|
-
input1
|
|
977
|
-
);
|
|
1014
|
+
expect(document.activeElement).to.equal(input1);
|
|
978
1015
|
});
|
|
979
1016
|
it("can close and immediately tab to the next tab stop", async () => {
|
|
980
1017
|
el.focus();
|
|
981
|
-
await nextFrame();
|
|
982
1018
|
expect(document.activeElement, "focuses el").to.equal(el);
|
|
983
1019
|
const opened = oneEvent(el, "sp-opened");
|
|
984
1020
|
await sendKeys({ press: "ArrowUp" });
|
|
985
1021
|
await opened;
|
|
986
1022
|
expect(el.open, "opened").to.be.true;
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
);
|
|
991
|
-
|
|
992
|
-
el.open = false;
|
|
993
|
-
await closed;
|
|
994
|
-
expect(el.open).to.be.false;
|
|
995
|
-
expect(document.activeElement === el).to.be.true;
|
|
996
|
-
const focused = oneEvent(input2, "focus");
|
|
1023
|
+
const closed2 = oneEvent(el, "sp-closed");
|
|
1024
|
+
el.close();
|
|
1025
|
+
await closed2;
|
|
1026
|
+
expect(el.open, "open?").to.be.false;
|
|
1027
|
+
expect(document.activeElement).to.equal(el);
|
|
997
1028
|
await sendKeys({ press: "Tab" });
|
|
998
|
-
|
|
999
|
-
expect(
|
|
1000
|
-
expect(document.activeElement === input2).to.be.true;
|
|
1029
|
+
expect(el.open, "open?").to.be.false;
|
|
1030
|
+
expect(document.activeElement).to.equal(input2);
|
|
1001
1031
|
});
|
|
1002
1032
|
it("can close and immediate shift+tab to the previous tab stop", async () => {
|
|
1003
1033
|
el.focus();
|
|
@@ -1007,20 +1037,16 @@ export function runPickerTests() {
|
|
|
1007
1037
|
await sendKeys({ press: "ArrowUp" });
|
|
1008
1038
|
await opened;
|
|
1009
1039
|
expect(el.open, "opened").to.be.true;
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
);
|
|
1014
|
-
|
|
1015
|
-
el.open = false;
|
|
1016
|
-
await closed;
|
|
1017
|
-
expect(el.open).to.be.false;
|
|
1018
|
-
expect(document.activeElement === el).to.be.true;
|
|
1040
|
+
const closed2 = oneEvent(el, "sp-closed");
|
|
1041
|
+
el.close();
|
|
1042
|
+
await closed2;
|
|
1043
|
+
expect(el.open, "open?").to.be.false;
|
|
1044
|
+
expect(document.activeElement).to.equal(el);
|
|
1019
1045
|
const focused = oneEvent(input1, "focus");
|
|
1020
1046
|
sendKeys({ press: "Shift+Tab" });
|
|
1021
1047
|
await focused;
|
|
1022
|
-
expect(el.open).to.be.false;
|
|
1023
|
-
expect(document.activeElement === input1).to.be.true;
|
|
1048
|
+
expect(el.open, "open?").to.be.false;
|
|
1049
|
+
expect(document.activeElement === input1, "input has focus").to.be.true;
|
|
1024
1050
|
});
|
|
1025
1051
|
});
|
|
1026
1052
|
it("does not open when [readonly]", async () => {
|
|
@@ -1028,7 +1054,7 @@ export function runPickerTests() {
|
|
|
1028
1054
|
await elementUpdated(el);
|
|
1029
1055
|
el.click();
|
|
1030
1056
|
await elementUpdated(el);
|
|
1031
|
-
expect(el.open).to.be.false;
|
|
1057
|
+
expect(el.open, "open?").to.be.false;
|
|
1032
1058
|
});
|
|
1033
1059
|
it("scrolls selected into view on open", async () => {
|
|
1034
1060
|
const styles = document.createElement("style");
|
|
@@ -1044,12 +1070,14 @@ export function runPickerTests() {
|
|
|
1044
1070
|
el.value = lastItem.value;
|
|
1045
1071
|
await elementUpdated(el);
|
|
1046
1072
|
const opened = oneEvent(el, "sp-opened");
|
|
1047
|
-
el.
|
|
1073
|
+
el.focus();
|
|
1074
|
+
await sendKeys({
|
|
1075
|
+
press: "ArrowDown"
|
|
1076
|
+
});
|
|
1048
1077
|
await opened;
|
|
1049
|
-
await waitUntil(
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
);
|
|
1078
|
+
await waitUntil(() => isMenuActiveElement(el), "menu item focused");
|
|
1079
|
+
await nextFrame();
|
|
1080
|
+
await nextFrame();
|
|
1053
1081
|
const getParentOffset = (el2) => {
|
|
1054
1082
|
const parentScroll = el2.assignedSlot.parentElement.scrollTop;
|
|
1055
1083
|
const parentOffset = el2.offsetTop - parentScroll;
|
|
@@ -1057,9 +1085,6 @@ export function runPickerTests() {
|
|
|
1057
1085
|
};
|
|
1058
1086
|
expect(getParentOffset(lastItem)).to.be.lessThan(40);
|
|
1059
1087
|
expect(getParentOffset(firstItem)).to.be.lessThan(-1);
|
|
1060
|
-
lastItem.dispatchEvent(
|
|
1061
|
-
new FocusEvent("focusin", { bubbles: true })
|
|
1062
|
-
);
|
|
1063
1088
|
await sendKeys({
|
|
1064
1089
|
press: "ArrowDown"
|
|
1065
1090
|
});
|
|
@@ -1091,19 +1116,18 @@ export function runPickerTests() {
|
|
|
1091
1116
|
});
|
|
1092
1117
|
await opened;
|
|
1093
1118
|
const tray = el.shadowRoot.querySelector("sp-tray");
|
|
1094
|
-
expect(tray).to.not.be.null;
|
|
1095
|
-
let
|
|
1119
|
+
expect(tray, "has tray").to.not.be.null;
|
|
1120
|
+
let closed2 = oneEvent(el, "sp-closed");
|
|
1096
1121
|
const firstItem = el.querySelector("sp-menu-item");
|
|
1097
1122
|
firstItem.click();
|
|
1098
|
-
await
|
|
1099
|
-
|
|
1100
|
-
expect(el.open).to.be.false;
|
|
1123
|
+
await closed2;
|
|
1124
|
+
expect(el.open, "open?").to.be.false;
|
|
1101
1125
|
const button = el.shadowRoot.querySelector(
|
|
1102
1126
|
"#button"
|
|
1103
1127
|
);
|
|
1104
|
-
expect(button).to.not.be.null;
|
|
1105
|
-
expect(button.classList.contains(SAFARI_FOCUS_RING_CLASS)).to.be.true;
|
|
1106
|
-
expect(document.activeElement
|
|
1128
|
+
expect(button, "has button").to.not.be.null;
|
|
1129
|
+
expect(button.classList.contains(SAFARI_FOCUS_RING_CLASS), "has focus ring?").to.be.true;
|
|
1130
|
+
expect(document.activeElement).to.equal(el);
|
|
1107
1131
|
await sendMouse({
|
|
1108
1132
|
steps: [
|
|
1109
1133
|
{
|
|
@@ -1112,22 +1136,18 @@ export function runPickerTests() {
|
|
|
1112
1136
|
}
|
|
1113
1137
|
]
|
|
1114
1138
|
});
|
|
1115
|
-
expect(document.activeElement
|
|
1139
|
+
expect(document.activeElement).not.to.equal(el);
|
|
1116
1140
|
opened = oneEvent(el, "sp-opened");
|
|
1117
|
-
|
|
1118
|
-
press: "Tab"
|
|
1119
|
-
});
|
|
1141
|
+
el.focus();
|
|
1120
1142
|
await sendKeys({
|
|
1121
1143
|
press: "Enter"
|
|
1122
1144
|
});
|
|
1123
|
-
await elementUpdated(el);
|
|
1124
1145
|
await opened;
|
|
1125
|
-
|
|
1146
|
+
closed2 = oneEvent(el, "sp-closed");
|
|
1126
1147
|
firstItem.click();
|
|
1127
|
-
await
|
|
1128
|
-
|
|
1129
|
-
expect(
|
|
1130
|
-
expect(button.classList.contains(SAFARI_FOCUS_RING_CLASS)).to.be.false;
|
|
1148
|
+
await closed2;
|
|
1149
|
+
expect(el.open, "open?").to.be.false;
|
|
1150
|
+
expect(button.classList.contains(SAFARI_FOCUS_RING_CLASS), "has focus ring?").to.be.false;
|
|
1131
1151
|
});
|
|
1132
1152
|
});
|
|
1133
1153
|
describe("grouped", async () => {
|
|
@@ -1197,10 +1217,10 @@ export function runPickerTests() {
|
|
|
1197
1217
|
await nextFrame();
|
|
1198
1218
|
});
|
|
1199
1219
|
afterEach(async () => {
|
|
1200
|
-
if (el.open) {
|
|
1201
|
-
const
|
|
1220
|
+
if (el && el.open) {
|
|
1221
|
+
const closed2 = oneEvent(el, "sp-closed");
|
|
1202
1222
|
el.open = false;
|
|
1203
|
-
await
|
|
1223
|
+
await closed2;
|
|
1204
1224
|
}
|
|
1205
1225
|
});
|
|
1206
1226
|
it("loads accessibly w/ slotted label", async () => {
|
|
@@ -1219,10 +1239,10 @@ export function runPickerTests() {
|
|
|
1219
1239
|
after(async () => {
|
|
1220
1240
|
window.__swc.verbose = false;
|
|
1221
1241
|
consoleWarnStub.restore();
|
|
1222
|
-
if (el.open) {
|
|
1223
|
-
const
|
|
1242
|
+
if (el == null ? void 0 : el.open) {
|
|
1243
|
+
const closed2 = oneEvent(el, "sp-closed");
|
|
1224
1244
|
el.open = false;
|
|
1225
|
-
await
|
|
1245
|
+
await closed2;
|
|
1226
1246
|
}
|
|
1227
1247
|
});
|
|
1228
1248
|
const pickerFixture2 = async () => {
|
|
@@ -1332,9 +1352,9 @@ export function runPickerTests() {
|
|
|
1332
1352
|
});
|
|
1333
1353
|
afterEach(async () => {
|
|
1334
1354
|
if (el.open) {
|
|
1335
|
-
const
|
|
1355
|
+
const closed2 = oneEvent(el, "sp-closed");
|
|
1336
1356
|
el.open = false;
|
|
1337
|
-
await
|
|
1357
|
+
await closed2;
|
|
1338
1358
|
}
|
|
1339
1359
|
});
|
|
1340
1360
|
it("selects with deprecated syntax", async () => {
|
|
@@ -1345,13 +1365,13 @@ export function runPickerTests() {
|
|
|
1345
1365
|
const opened = oneEvent(el, "sp-opened");
|
|
1346
1366
|
el.click();
|
|
1347
1367
|
await opened;
|
|
1348
|
-
expect(el.open).to.be.true;
|
|
1368
|
+
expect(el.open, "open?").to.be.true;
|
|
1349
1369
|
expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
|
|
1350
1370
|
expect(el.value).to.equal("");
|
|
1351
|
-
const
|
|
1371
|
+
const closed2 = oneEvent(el, "sp-closed");
|
|
1352
1372
|
secondItem.click();
|
|
1353
|
-
await
|
|
1354
|
-
expect(el.open).to.be.false;
|
|
1373
|
+
await closed2;
|
|
1374
|
+
expect(el.open, "open?").to.be.false;
|
|
1355
1375
|
expect((_b = el.selectedItem) == null ? void 0 : _b.itemText).to.equal("Select Inverse");
|
|
1356
1376
|
expect(el.value).to.equal("option-2");
|
|
1357
1377
|
});
|
|
@@ -1388,41 +1408,39 @@ export function runPickerTests() {
|
|
|
1388
1408
|
).to.not.be.null;
|
|
1389
1409
|
});
|
|
1390
1410
|
it("toggles between pickers", async () => {
|
|
1391
|
-
const el2 = await pickerFixture();
|
|
1392
1411
|
const el1 = await pickerFixture();
|
|
1393
|
-
|
|
1394
|
-
el2.parentElement.style.float = "left";
|
|
1412
|
+
const el2 = await pickerFixture();
|
|
1395
1413
|
el1.id = "away";
|
|
1396
1414
|
el2.id = "other";
|
|
1397
|
-
|
|
1398
|
-
expect(
|
|
1399
|
-
|
|
1400
|
-
let
|
|
1415
|
+
expect(el1.open, "el1 to be closed").to.be.false;
|
|
1416
|
+
expect(el2.open, "el2 to be closed").to.be.false;
|
|
1417
|
+
const el1open = oneEvent(el1, "sp-opened");
|
|
1418
|
+
let el1closed = oneEvent(el1, "sp-closed");
|
|
1419
|
+
const el2open = oneEvent(el2, "sp-opened");
|
|
1420
|
+
const el2closed = oneEvent(el2, "sp-closed");
|
|
1401
1421
|
el1.click();
|
|
1402
|
-
await
|
|
1403
|
-
expect(el1.open).to.be.true;
|
|
1404
|
-
expect(el2.open).to.be.false;
|
|
1405
|
-
open = oneEvent(el2, "sp-opened");
|
|
1406
|
-
let closed = oneEvent(el1, "sp-closed");
|
|
1422
|
+
await el1open;
|
|
1423
|
+
expect(el1.open, "click el1: el1 to be open").to.be.true;
|
|
1424
|
+
expect(el2.open, "click el1: el2 to be closed").to.be.false;
|
|
1407
1425
|
el2.click();
|
|
1408
|
-
await
|
|
1409
|
-
|
|
1410
|
-
expect(
|
|
1411
|
-
open
|
|
1412
|
-
closed = oneEvent(el2, "sp-closed");
|
|
1426
|
+
await el1closed;
|
|
1427
|
+
await el2open;
|
|
1428
|
+
expect(el1.open, "click el2: el1 to be closed").to.be.false;
|
|
1429
|
+
expect(el2.open, "click el2: el2 to be open").to.be.true;
|
|
1413
1430
|
el1.click();
|
|
1414
|
-
await
|
|
1415
|
-
|
|
1416
|
-
expect(
|
|
1417
|
-
|
|
1431
|
+
await el2closed;
|
|
1432
|
+
await el1open;
|
|
1433
|
+
expect(el2.open, "click el1 again: el2 to be closed").to.be.false;
|
|
1434
|
+
expect(el1.open, "click el1 again: el1 to be open").to.be.true;
|
|
1435
|
+
el1closed = oneEvent(el1, "sp-closed");
|
|
1418
1436
|
sendKeys({
|
|
1419
1437
|
press: "Escape"
|
|
1420
1438
|
});
|
|
1421
|
-
await
|
|
1422
|
-
expect(el1.open).to.be.false;
|
|
1439
|
+
await el1closed;
|
|
1440
|
+
expect(el1.open, "escape key: el1 to be closed").to.be.false;
|
|
1423
1441
|
});
|
|
1424
1442
|
it("displays selected item text by default", async () => {
|
|
1425
|
-
var _a, _b, _c, _d
|
|
1443
|
+
var _a, _b, _c, _d;
|
|
1426
1444
|
const el2 = await fixture(html`
|
|
1427
1445
|
<sp-picker
|
|
1428
1446
|
value="inverse"
|
|
@@ -1463,20 +1481,11 @@ export function runPickerTests() {
|
|
|
1463
1481
|
sendKeys({ press: "Enter" });
|
|
1464
1482
|
await opened;
|
|
1465
1483
|
expect(
|
|
1466
|
-
el2 === document.activeElement,
|
|
1484
|
+
el2.selectedItem === document.activeElement,
|
|
1467
1485
|
`activeElement is ${(_d = document.activeElement) == null ? void 0 : _d.localName}`
|
|
1468
1486
|
).to.be.true;
|
|
1469
|
-
expect(
|
|
1470
|
-
el2.optionsMenu === el2.shadowRoot.activeElement,
|
|
1471
|
-
`activeElement is ${(_e = el2.shadowRoot.activeElement) == null ? void 0 : _e.localName}`
|
|
1472
|
-
).to.be.true;
|
|
1473
1487
|
expect(firstItem.focused, 'firstItem NOT "focused"').to.be.false;
|
|
1474
1488
|
expect(secondItem.focused, 'secondItem "focused"').to.be.true;
|
|
1475
|
-
expect(
|
|
1476
|
-
el2.optionsMenu.getAttribute(
|
|
1477
|
-
"aria-activedescendant"
|
|
1478
|
-
)
|
|
1479
|
-
).to.equal(secondItem.id);
|
|
1480
1489
|
});
|
|
1481
1490
|
it("resets value when item not available", async () => {
|
|
1482
1491
|
var _a;
|
|
@@ -1516,15 +1525,15 @@ export function runPickerTests() {
|
|
|
1516
1525
|
el2.open = true;
|
|
1517
1526
|
await opened;
|
|
1518
1527
|
await elementUpdated(el2);
|
|
1519
|
-
expect(el2.open).to.be.true;
|
|
1528
|
+
expect(el2.open, "open?").to.be.true;
|
|
1520
1529
|
hoverEl.dispatchEvent(new MouseEvent("mouseenter"));
|
|
1521
1530
|
await elementUpdated(el2);
|
|
1522
|
-
expect(el2.open).to.be.true;
|
|
1523
|
-
const
|
|
1531
|
+
expect(el2.open, "open?").to.be.true;
|
|
1532
|
+
const closed2 = oneEvent(el2, "sp-closed");
|
|
1524
1533
|
el2.open = false;
|
|
1525
|
-
await
|
|
1534
|
+
await closed2;
|
|
1526
1535
|
await elementUpdated(el2);
|
|
1527
|
-
expect(el2.open).to.be.false;
|
|
1536
|
+
expect(el2.open, "open?").to.be.false;
|
|
1528
1537
|
expect(mouseenterSpy.calledOnce).to.be.true;
|
|
1529
1538
|
});
|
|
1530
1539
|
it("dispatches events on open/close", async () => {
|
|
@@ -1548,9 +1557,9 @@ export function runPickerTests() {
|
|
|
1548
1557
|
await elementUpdated(el2);
|
|
1549
1558
|
expect(openedSpy.calledOnce).to.be.true;
|
|
1550
1559
|
expect(closedSpy.calledOnce).to.be.false;
|
|
1551
|
-
const
|
|
1560
|
+
const closed2 = oneEvent(el2, "sp-closed");
|
|
1552
1561
|
el2.open = false;
|
|
1553
|
-
await
|
|
1562
|
+
await closed2;
|
|
1554
1563
|
await elementUpdated(el2);
|
|
1555
1564
|
expect(closedSpy.calledOnce).to.be.true;
|
|
1556
1565
|
});
|
|
@@ -1563,23 +1572,29 @@ export function runPickerTests() {
|
|
|
1563
1572
|
await elementUpdated(el2);
|
|
1564
1573
|
const input1 = document.createElement("input");
|
|
1565
1574
|
const input2 = document.createElement("input");
|
|
1575
|
+
input1.id = "input1";
|
|
1576
|
+
input2.id = "input2";
|
|
1566
1577
|
const tooltipEl = el2.querySelector("sp-tooltip");
|
|
1567
1578
|
el2.insertAdjacentElement("beforebegin", input1);
|
|
1568
1579
|
el2.insertAdjacentElement("afterend", input2);
|
|
1569
1580
|
input1.focus();
|
|
1570
|
-
expect(document.activeElement
|
|
1581
|
+
expect(document.activeElement).to.equal(input1);
|
|
1571
1582
|
const tooltipOpened = oneEvent(el2, "sp-opened");
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1583
|
+
if (!isSafari) {
|
|
1584
|
+
await sendKeys({
|
|
1585
|
+
press: "Tab"
|
|
1586
|
+
});
|
|
1587
|
+
} else {
|
|
1588
|
+
el2.focus();
|
|
1589
|
+
}
|
|
1575
1590
|
await tooltipOpened;
|
|
1576
1591
|
expect(
|
|
1577
1592
|
document.activeElement === el2,
|
|
1578
1593
|
`Actually, ${(_a = document.activeElement) == null ? void 0 : _a.localName}`
|
|
1579
1594
|
).to.be.true;
|
|
1580
|
-
expect(tooltipEl.open).to.be.true;
|
|
1581
|
-
expect(el2.open).to.be.false;
|
|
1582
|
-
expect(el2.focused).to.be.true;
|
|
1595
|
+
expect(tooltipEl.open, "tooltipEl open?").to.be.true;
|
|
1596
|
+
expect(el2.open, "open?").to.be.false;
|
|
1597
|
+
expect(el2.focused, "el focused?").to.be.true;
|
|
1583
1598
|
const menuOpen = oneEvent(el2, "sp-opened");
|
|
1584
1599
|
const tooltipClosed = oneEvent(el2, "sp-closed");
|
|
1585
1600
|
await sendKeys({
|
|
@@ -1587,17 +1602,21 @@ export function runPickerTests() {
|
|
|
1587
1602
|
});
|
|
1588
1603
|
await menuOpen;
|
|
1589
1604
|
await tooltipClosed;
|
|
1590
|
-
|
|
1591
|
-
expect(
|
|
1592
|
-
|
|
1605
|
+
const firstOption = el2.querySelector("sp-menu-item");
|
|
1606
|
+
expect(
|
|
1607
|
+
document.activeElement === firstOption,
|
|
1608
|
+
"firstOption is activeElement"
|
|
1609
|
+
).to.be.true;
|
|
1610
|
+
expect(tooltipEl.open, "tooltip open").to.be.false;
|
|
1611
|
+
expect(el2.open, "menu open").to.be.true;
|
|
1593
1612
|
const menuClosed = oneEvent(el2, "sp-closed");
|
|
1594
1613
|
await sendKeys({
|
|
1595
1614
|
press: "Tab"
|
|
1596
1615
|
});
|
|
1597
1616
|
await menuClosed;
|
|
1598
|
-
expect(document.activeElement
|
|
1599
|
-
expect(tooltipEl.open).to.be.false;
|
|
1600
|
-
expect(el2.open).to.be.false;
|
|
1617
|
+
expect(document.activeElement).not.to.equal(el2);
|
|
1618
|
+
expect(tooltipEl.open, "tooltipEl open?").to.be.false;
|
|
1619
|
+
expect(el2.open, "open?").to.be.false;
|
|
1601
1620
|
});
|
|
1602
1621
|
describe("disabled", function() {
|
|
1603
1622
|
beforeEach(async function() {
|
|
@@ -1609,22 +1628,22 @@ export function runPickerTests() {
|
|
|
1609
1628
|
await elementUpdated(this.elel);
|
|
1610
1629
|
});
|
|
1611
1630
|
it("does not recieve focus from an `<sp-field-label>`", async function() {
|
|
1612
|
-
expect(this.el.disabled).to.be.true;
|
|
1613
|
-
expect(this.el.focused).to.be.false;
|
|
1631
|
+
expect(this.el.disabled, "this.el disabled?").to.be.true;
|
|
1632
|
+
expect(this.el.focused, "this.el focused?").to.be.false;
|
|
1614
1633
|
this.label.click();
|
|
1615
1634
|
await elementUpdated(this.el);
|
|
1616
|
-
expect(this.el.focused).to.be.false;
|
|
1635
|
+
expect(this.el.focused, "this.el focused?").to.be.false;
|
|
1617
1636
|
});
|
|
1618
1637
|
it("does not open from `click()`", async function() {
|
|
1619
|
-
expect(this.el.disabled).to.be.true;
|
|
1620
|
-
expect(this.el.open).to.be.false;
|
|
1638
|
+
expect(this.el.disabled, "this.el disabled?").to.be.true;
|
|
1639
|
+
expect(this.el.focused, "this.el open?").to.be.false;
|
|
1621
1640
|
this.el.click();
|
|
1622
1641
|
await elementUpdated(this.el);
|
|
1623
|
-
expect(this.el.open).to.be.false;
|
|
1642
|
+
expect(this.el.focused, "this.el open?").to.be.false;
|
|
1624
1643
|
});
|
|
1625
1644
|
it("does not open from `sendMouse()`", async function() {
|
|
1626
|
-
expect(this.el.disabled).to.be.true;
|
|
1627
|
-
expect(this.el.open).to.be.false;
|
|
1645
|
+
expect(this.el.disabled, "this.el disabled?").to.be.true;
|
|
1646
|
+
expect(this.el.focused, "this.el open?").to.be.false;
|
|
1628
1647
|
const boundingRect = this.el.button.getBoundingClientRect();
|
|
1629
1648
|
sendMouse({
|
|
1630
1649
|
steps: [
|
|
@@ -1641,7 +1660,7 @@ export function runPickerTests() {
|
|
|
1641
1660
|
await nextFrame();
|
|
1642
1661
|
await nextFrame();
|
|
1643
1662
|
await nextFrame();
|
|
1644
|
-
expect(this.el.open).to.be.false;
|
|
1663
|
+
expect(this.el.focused, "this.el open?").to.be.false;
|
|
1645
1664
|
});
|
|
1646
1665
|
});
|
|
1647
1666
|
describe("pending", function() {
|
|
@@ -1654,16 +1673,16 @@ export function runPickerTests() {
|
|
|
1654
1673
|
await elementUpdated(this.elel);
|
|
1655
1674
|
});
|
|
1656
1675
|
it("receives focus from an `<sp-field-label>`", async function() {
|
|
1657
|
-
expect(this.el.focused).to.be.false;
|
|
1676
|
+
expect(this.el.focused, "this.el focused?").to.be.false;
|
|
1658
1677
|
this.label.click();
|
|
1659
1678
|
await elementUpdated(this.el);
|
|
1660
|
-
expect(this.el.focused).to.be.true;
|
|
1679
|
+
expect(this.el.focused, "this.el focused?").to.be.true;
|
|
1661
1680
|
});
|
|
1662
1681
|
it("does not open from `click()`", async function() {
|
|
1663
|
-
expect(this.el.open).to.be.false;
|
|
1682
|
+
expect(this.el.focused, "this.el open?").to.be.false;
|
|
1664
1683
|
this.el.click();
|
|
1665
1684
|
await elementUpdated(this.el);
|
|
1666
|
-
expect(this.el.open).to.be.false;
|
|
1685
|
+
expect(this.el.focused, "this.el open?").to.be.false;
|
|
1667
1686
|
});
|
|
1668
1687
|
it('manages its "name" value in the accessibility tree when [pending]', async () => {
|
|
1669
1688
|
const snapshot = await a11ySnapshot(
|
|
@@ -1689,6 +1708,7 @@ export function runPickerTests() {
|
|
|
1689
1708
|
await nextFrame();
|
|
1690
1709
|
await nextFrame();
|
|
1691
1710
|
await nextFrame();
|
|
1711
|
+
await nextFrame();
|
|
1692
1712
|
const picker = this.el;
|
|
1693
1713
|
const displayedIconBefore = picker.shadowRoot.querySelector("#icon > sp-icon");
|
|
1694
1714
|
expect(displayedIconBefore).to.be.ok;
|