@spectrum-web-components/picker 0.40.3 → 0.40.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/test/index.js CHANGED
@@ -407,6 +407,39 @@ export function runPickerTests() {
407
407
  "finally, not visually focused"
408
408
  );
409
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
+ });
410
443
  it("opens, on click, without visible focus on a menu item", async () => {
411
444
  await nextFrame();
412
445
  await nextFrame();
@@ -429,6 +462,50 @@ export function runPickerTests() {
429
462
  expect(el.open).to.be.true;
430
463
  expect(firstItem.focused, "still not visually focused").to.be.false;
431
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
+ });
432
509
  it("opens/closes multiple times", async () => {
433
510
  expect(el.open).to.be.false;
434
511
  const boundingRect = el.button.getBoundingClientRect();
@@ -520,9 +597,8 @@ export function runPickerTests() {
520
597
  const secondItem = el.querySelector(
521
598
  "sp-menu-item:nth-of-type(2)"
522
599
  );
523
- const button = el.button;
524
600
  const opened = oneEvent(el, "sp-opened");
525
- button.click();
601
+ el.click();
526
602
  await opened;
527
603
  expect(el.open).to.be.true;
528
604
  expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
@@ -542,9 +618,8 @@ export function runPickerTests() {
542
618
  const secondItem = el.querySelector(
543
619
  "sp-menu-item:nth-of-type(2)"
544
620
  );
545
- const button = el.button;
546
621
  let opened = oneEvent(el, "sp-opened");
547
- button.click();
622
+ el.click();
548
623
  await opened;
549
624
  expect(el.open).to.be.true;
550
625
  expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
@@ -556,7 +631,7 @@ export function runPickerTests() {
556
631
  expect((_b = el.selectedItem) == null ? void 0 : _b.itemText).to.equal("Select Inverse");
557
632
  expect(el.value).to.equal("option-2");
558
633
  opened = oneEvent(el, "sp-opened");
559
- button.click();
634
+ el.click();
560
635
  await opened;
561
636
  expect(el.open).to.be.true;
562
637
  expect((_c = el.selectedItem) == null ? void 0 : _c.itemText).to.equal("Select Inverse");
@@ -592,9 +667,8 @@ export function runPickerTests() {
592
667
  const secondItem = el.querySelector(
593
668
  "sp-menu-item:nth-of-type(2)"
594
669
  );
595
- const button = el.button;
596
670
  const opened = oneEvent(el, "sp-opened");
597
- button.click();
671
+ el.click();
598
672
  await opened;
599
673
  expect(el.open).to.be.true;
600
674
  expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
@@ -619,9 +693,8 @@ export function runPickerTests() {
619
693
  const secondItem = el.querySelector(
620
694
  "sp-menu-item:nth-of-type(2)"
621
695
  );
622
- const button = el.button;
623
696
  const opened = oneEvent(el, "sp-opened");
624
- button.click();
697
+ el.click();
625
698
  await opened;
626
699
  await elementUpdated(el);
627
700
  expect(el.open).to.be.true;
@@ -940,8 +1013,7 @@ export function runPickerTests() {
940
1013
  it("does not open when [readonly]", async () => {
941
1014
  el.readonly = true;
942
1015
  await elementUpdated(el);
943
- const button = el.button;
944
- button.click();
1016
+ el.click();
945
1017
  await elementUpdated(el);
946
1018
  expect(el.open).to.be.false;
947
1019
  });
@@ -1065,7 +1137,24 @@ export function runPickerTests() {
1065
1137
  await expect(el).to.be.accessible();
1066
1138
  });
1067
1139
  });
1068
- describe("deprecated", () => {
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
+ });
1069
1158
  const pickerFixture2 = async () => {
1070
1159
  const test = await fixture(
1071
1160
  html`
@@ -1095,9 +1184,31 @@ export function runPickerTests() {
1095
1184
  );
1096
1185
  return test.querySelector("sp-picker");
1097
1186
  };
1098
- describe("Dev mode", () => {
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", () => {
1099
1211
  it("warns in Dev Mode of deprecated `<sp-menu>` usage", async () => {
1100
- const consoleWarnStub = stub(console, "warn");
1101
1212
  el = await pickerFixture2();
1102
1213
  await elementUpdated(el);
1103
1214
  expect(consoleWarnStub.called).to.be.true;
@@ -1116,12 +1227,6 @@ export function runPickerTests() {
1116
1227
  level: "deprecation"
1117
1228
  }
1118
1229
  });
1119
- consoleWarnStub.restore();
1120
- if (el.open) {
1121
- const closed = oneEvent(el, "sp-closed");
1122
- el.open = false;
1123
- await closed;
1124
- }
1125
1230
  });
1126
1231
  });
1127
1232
  describe("Dev mode ignored", () => {
@@ -1152,7 +1257,7 @@ export function runPickerTests() {
1152
1257
  "sp-menu-item:nth-of-type(2)"
1153
1258
  );
1154
1259
  const opened = oneEvent(el, "sp-opened");
1155
- el.button.click();
1260
+ el.click();
1156
1261
  await opened;
1157
1262
  expect(el.open).to.be.true;
1158
1263
  expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;