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