@spectrum-web-components/picker 0.40.2 → 0.40.4
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/README.md +1 -1
- package/custom-elements.json +242 -4
- package/package.json +15 -14
- package/src/Picker.d.ts +12 -2
- package/src/Picker.dev.js +94 -21
- package/src/Picker.dev.js.map +3 -3
- package/src/Picker.js +33 -24
- package/src/Picker.js.map +3 -3
- package/src/picker.css.dev.js +40 -40
- package/src/picker.css.dev.js.map +1 -1
- package/src/picker.css.js +40 -40
- package/src/picker.css.js.map +1 -1
- package/src/spectrum-config.js +1 -1
- package/src/spectrum-picker.css.dev.js +39 -39
- package/src/spectrum-picker.css.dev.js.map +1 -1
- package/src/spectrum-picker.css.js +39 -39
- package/src/spectrum-picker.css.js.map +1 -1
- package/test/index.js +128 -34
- package/test/index.js.map +2 -2
package/test/index.js
CHANGED
|
@@ -35,7 +35,6 @@ import {
|
|
|
35
35
|
ignoreResizeObserverLoopError,
|
|
36
36
|
fixture as styledFixture
|
|
37
37
|
} from "../../../test/testing-helpers.js";
|
|
38
|
-
import { isFirefox } from "@spectrum-web-components/shared/src/platform.js";
|
|
39
38
|
import "@spectrum-web-components/picker/sp-picker.js";
|
|
40
39
|
import "@spectrum-web-components/field-label/sp-field-label.js";
|
|
41
40
|
import "@spectrum-web-components/menu/sp-menu.js";
|
|
@@ -75,7 +74,7 @@ export function runPickerTests() {
|
|
|
75
74
|
return test.querySelector("sp-picker");
|
|
76
75
|
};
|
|
77
76
|
describe("accessibility model", () => {
|
|
78
|
-
it('accessible with "<sp-field-label>"', async ()
|
|
77
|
+
it('accessible with "<sp-field-label>"', async function() {
|
|
79
78
|
const test = await fixture(html`
|
|
80
79
|
<div>
|
|
81
80
|
${Default({
|
|
@@ -139,7 +138,7 @@ export function runPickerTests() {
|
|
|
139
138
|
"`name` is the the selected item text plus the label text"
|
|
140
139
|
).to.not.be.null;
|
|
141
140
|
});
|
|
142
|
-
it('accessible with "label" slot', async ()
|
|
141
|
+
it('accessible with "label" slot', async function() {
|
|
143
142
|
const test = await fixture(html`
|
|
144
143
|
<div>
|
|
145
144
|
${slottedLabel({
|
|
@@ -163,16 +162,6 @@ export function runPickerTests() {
|
|
|
163
162
|
await nextFrame();
|
|
164
163
|
await nextFrame();
|
|
165
164
|
snapshot = await a11ySnapshot({});
|
|
166
|
-
if (isFirefox()) {
|
|
167
|
-
expect(
|
|
168
|
-
findAccessibilityNode(
|
|
169
|
-
snapshot,
|
|
170
|
-
(node) => node.name === "Select Inverse"
|
|
171
|
-
),
|
|
172
|
-
"`name` is the the selected item text without label test"
|
|
173
|
-
).to.not.be.null;
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
165
|
expect(
|
|
177
166
|
findAccessibilityNode(
|
|
178
167
|
snapshot,
|
|
@@ -418,6 +407,39 @@ export function runPickerTests() {
|
|
|
418
407
|
"finally, not visually focused"
|
|
419
408
|
);
|
|
420
409
|
});
|
|
410
|
+
it("opens with visible focus on a menu item on `Space`", async function() {
|
|
411
|
+
var _a, _b;
|
|
412
|
+
const firstItem = el.querySelector("sp-menu-item");
|
|
413
|
+
await elementUpdated(el);
|
|
414
|
+
expect(firstItem.focused, "should not visually focused").to.be.false;
|
|
415
|
+
el.focus();
|
|
416
|
+
await elementUpdated(el);
|
|
417
|
+
const opened = oneEvent(el, "sp-opened");
|
|
418
|
+
await sendKeys({ press: "ArrowRight" });
|
|
419
|
+
await sendKeys({ press: "ArrowLeft" });
|
|
420
|
+
await sendKeys({ press: "Space" });
|
|
421
|
+
await opened;
|
|
422
|
+
expect(el.open).to.be.true;
|
|
423
|
+
expect(firstItem.focused, "should be visually focused").to.be.true;
|
|
424
|
+
const closed = oneEvent(el, "sp-closed");
|
|
425
|
+
await sendKeys({
|
|
426
|
+
press: "Escape"
|
|
427
|
+
});
|
|
428
|
+
await closed;
|
|
429
|
+
expect(el.open).to.be.false;
|
|
430
|
+
expect(
|
|
431
|
+
document.activeElement === el,
|
|
432
|
+
`focused ${(_a = document.activeElement) == null ? void 0 : _a.localName} instead of back on Picker`
|
|
433
|
+
).to.be.true;
|
|
434
|
+
expect(
|
|
435
|
+
el.shadowRoot.activeElement === el.button,
|
|
436
|
+
`focused ${(_b = el.shadowRoot.activeElement) == null ? void 0 : _b.localName} instead of back on button`
|
|
437
|
+
).to.be.true;
|
|
438
|
+
await waitUntil(
|
|
439
|
+
() => !firstItem.focused,
|
|
440
|
+
"finally, not visually focused"
|
|
441
|
+
);
|
|
442
|
+
});
|
|
421
443
|
it("opens, on click, without visible focus on a menu item", async () => {
|
|
422
444
|
await nextFrame();
|
|
423
445
|
await nextFrame();
|
|
@@ -440,6 +462,50 @@ export function runPickerTests() {
|
|
|
440
462
|
expect(el.open).to.be.true;
|
|
441
463
|
expect(firstItem.focused, "still not visually focused").to.be.false;
|
|
442
464
|
});
|
|
465
|
+
it("opens and selects in a single pointer button interaction", async () => {
|
|
466
|
+
await nextFrame();
|
|
467
|
+
await nextFrame();
|
|
468
|
+
const thirdItem = el.querySelector(
|
|
469
|
+
"sp-menu-item:nth-of-type(3)"
|
|
470
|
+
);
|
|
471
|
+
const boundingRect = el.button.getBoundingClientRect();
|
|
472
|
+
expect(el.value).to.not.equal(thirdItem.value);
|
|
473
|
+
const opened = oneEvent(el, "sp-opened");
|
|
474
|
+
await sendMouse({
|
|
475
|
+
steps: [
|
|
476
|
+
{
|
|
477
|
+
type: "move",
|
|
478
|
+
position: [
|
|
479
|
+
boundingRect.x + boundingRect.width / 2,
|
|
480
|
+
boundingRect.y + boundingRect.height / 2
|
|
481
|
+
]
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
type: "down"
|
|
485
|
+
}
|
|
486
|
+
]
|
|
487
|
+
});
|
|
488
|
+
await opened;
|
|
489
|
+
const thirdItemRect = thirdItem.getBoundingClientRect();
|
|
490
|
+
const closed = oneEvent(el, "sp-closed");
|
|
491
|
+
await sendMouse({
|
|
492
|
+
steps: [
|
|
493
|
+
{
|
|
494
|
+
type: "move",
|
|
495
|
+
position: [
|
|
496
|
+
thirdItemRect.x + thirdItemRect.width / 2,
|
|
497
|
+
thirdItemRect.y + thirdItemRect.height / 2
|
|
498
|
+
]
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
type: "up"
|
|
502
|
+
}
|
|
503
|
+
]
|
|
504
|
+
});
|
|
505
|
+
await closed;
|
|
506
|
+
expect(el.open).to.be.false;
|
|
507
|
+
expect(el.value).to.equal(thirdItem.value);
|
|
508
|
+
});
|
|
443
509
|
it("opens/closes multiple times", async () => {
|
|
444
510
|
expect(el.open).to.be.false;
|
|
445
511
|
const boundingRect = el.button.getBoundingClientRect();
|
|
@@ -531,9 +597,8 @@ export function runPickerTests() {
|
|
|
531
597
|
const secondItem = el.querySelector(
|
|
532
598
|
"sp-menu-item:nth-of-type(2)"
|
|
533
599
|
);
|
|
534
|
-
const button = el.button;
|
|
535
600
|
const opened = oneEvent(el, "sp-opened");
|
|
536
|
-
|
|
601
|
+
el.click();
|
|
537
602
|
await opened;
|
|
538
603
|
expect(el.open).to.be.true;
|
|
539
604
|
expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
|
|
@@ -553,9 +618,8 @@ export function runPickerTests() {
|
|
|
553
618
|
const secondItem = el.querySelector(
|
|
554
619
|
"sp-menu-item:nth-of-type(2)"
|
|
555
620
|
);
|
|
556
|
-
const button = el.button;
|
|
557
621
|
let opened = oneEvent(el, "sp-opened");
|
|
558
|
-
|
|
622
|
+
el.click();
|
|
559
623
|
await opened;
|
|
560
624
|
expect(el.open).to.be.true;
|
|
561
625
|
expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
|
|
@@ -567,7 +631,7 @@ export function runPickerTests() {
|
|
|
567
631
|
expect((_b = el.selectedItem) == null ? void 0 : _b.itemText).to.equal("Select Inverse");
|
|
568
632
|
expect(el.value).to.equal("option-2");
|
|
569
633
|
opened = oneEvent(el, "sp-opened");
|
|
570
|
-
|
|
634
|
+
el.click();
|
|
571
635
|
await opened;
|
|
572
636
|
expect(el.open).to.be.true;
|
|
573
637
|
expect((_c = el.selectedItem) == null ? void 0 : _c.itemText).to.equal("Select Inverse");
|
|
@@ -603,9 +667,8 @@ export function runPickerTests() {
|
|
|
603
667
|
const secondItem = el.querySelector(
|
|
604
668
|
"sp-menu-item:nth-of-type(2)"
|
|
605
669
|
);
|
|
606
|
-
const button = el.button;
|
|
607
670
|
const opened = oneEvent(el, "sp-opened");
|
|
608
|
-
|
|
671
|
+
el.click();
|
|
609
672
|
await opened;
|
|
610
673
|
expect(el.open).to.be.true;
|
|
611
674
|
expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
|
|
@@ -630,9 +693,8 @@ export function runPickerTests() {
|
|
|
630
693
|
const secondItem = el.querySelector(
|
|
631
694
|
"sp-menu-item:nth-of-type(2)"
|
|
632
695
|
);
|
|
633
|
-
const button = el.button;
|
|
634
696
|
const opened = oneEvent(el, "sp-opened");
|
|
635
|
-
|
|
697
|
+
el.click();
|
|
636
698
|
await opened;
|
|
637
699
|
await elementUpdated(el);
|
|
638
700
|
expect(el.open).to.be.true;
|
|
@@ -951,8 +1013,7 @@ export function runPickerTests() {
|
|
|
951
1013
|
it("does not open when [readonly]", async () => {
|
|
952
1014
|
el.readonly = true;
|
|
953
1015
|
await elementUpdated(el);
|
|
954
|
-
|
|
955
|
-
button.click();
|
|
1016
|
+
el.click();
|
|
956
1017
|
await elementUpdated(el);
|
|
957
1018
|
expect(el.open).to.be.false;
|
|
958
1019
|
});
|
|
@@ -1076,7 +1137,24 @@ export function runPickerTests() {
|
|
|
1076
1137
|
await expect(el).to.be.accessible();
|
|
1077
1138
|
});
|
|
1078
1139
|
});
|
|
1079
|
-
describe("
|
|
1140
|
+
describe("Dev mode", () => {
|
|
1141
|
+
let consoleWarnStub;
|
|
1142
|
+
before(() => {
|
|
1143
|
+
window.__swc.verbose = true;
|
|
1144
|
+
consoleWarnStub = stub(console, "warn");
|
|
1145
|
+
});
|
|
1146
|
+
afterEach(() => {
|
|
1147
|
+
consoleWarnStub.resetHistory();
|
|
1148
|
+
});
|
|
1149
|
+
after(async () => {
|
|
1150
|
+
window.__swc.verbose = false;
|
|
1151
|
+
consoleWarnStub.restore();
|
|
1152
|
+
if (el.open) {
|
|
1153
|
+
const closed = oneEvent(el, "sp-closed");
|
|
1154
|
+
el.open = false;
|
|
1155
|
+
await closed;
|
|
1156
|
+
}
|
|
1157
|
+
});
|
|
1080
1158
|
const pickerFixture2 = async () => {
|
|
1081
1159
|
const test = await fixture(
|
|
1082
1160
|
html`
|
|
@@ -1106,9 +1184,31 @@ export function runPickerTests() {
|
|
|
1106
1184
|
);
|
|
1107
1185
|
return test.querySelector("sp-picker");
|
|
1108
1186
|
};
|
|
1109
|
-
|
|
1187
|
+
it("warns in Dev Mode when accessible attributes are not leveraged", async () => {
|
|
1188
|
+
el = await fixture(html`
|
|
1189
|
+
<sp-picker>
|
|
1190
|
+
<sp-menu-item>Feather...</sp-menu-item>
|
|
1191
|
+
<sp-menu-item>Select and Mask...</sp-menu-item>
|
|
1192
|
+
<sp-menu-item>Save Selection</sp-menu-item>
|
|
1193
|
+
</sp-picker>
|
|
1194
|
+
`);
|
|
1195
|
+
await elementUpdated(el);
|
|
1196
|
+
expect(consoleWarnStub.called).to.be.true;
|
|
1197
|
+
const spyCall = consoleWarnStub.getCall(0);
|
|
1198
|
+
expect(
|
|
1199
|
+
spyCall.args.at(0).includes("accessible"),
|
|
1200
|
+
"confirm accessibility-centric message"
|
|
1201
|
+
).to.be.true;
|
|
1202
|
+
expect(spyCall.args.at(-1), "confirm `data` shape").to.deep.equal({
|
|
1203
|
+
data: {
|
|
1204
|
+
localName: "sp-picker",
|
|
1205
|
+
type: "accessibility",
|
|
1206
|
+
level: "default"
|
|
1207
|
+
}
|
|
1208
|
+
});
|
|
1209
|
+
});
|
|
1210
|
+
describe("deprecated", () => {
|
|
1110
1211
|
it("warns in Dev Mode of deprecated `<sp-menu>` usage", async () => {
|
|
1111
|
-
const consoleWarnStub = stub(console, "warn");
|
|
1112
1212
|
el = await pickerFixture2();
|
|
1113
1213
|
await elementUpdated(el);
|
|
1114
1214
|
expect(consoleWarnStub.called).to.be.true;
|
|
@@ -1127,12 +1227,6 @@ export function runPickerTests() {
|
|
|
1127
1227
|
level: "deprecation"
|
|
1128
1228
|
}
|
|
1129
1229
|
});
|
|
1130
|
-
consoleWarnStub.restore();
|
|
1131
|
-
if (el.open) {
|
|
1132
|
-
const closed = oneEvent(el, "sp-closed");
|
|
1133
|
-
el.open = false;
|
|
1134
|
-
await closed;
|
|
1135
|
-
}
|
|
1136
1230
|
});
|
|
1137
1231
|
});
|
|
1138
1232
|
describe("Dev mode ignored", () => {
|
|
@@ -1163,7 +1257,7 @@ export function runPickerTests() {
|
|
|
1163
1257
|
"sp-menu-item:nth-of-type(2)"
|
|
1164
1258
|
);
|
|
1165
1259
|
const opened = oneEvent(el, "sp-opened");
|
|
1166
|
-
el.
|
|
1260
|
+
el.click();
|
|
1167
1261
|
await opened;
|
|
1168
1262
|
expect(el.open).to.be.true;
|
|
1169
1263
|
expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
|