@spectrum-web-components/picker 0.11.4 → 0.11.6-devmode.7

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.
Files changed (51) hide show
  1. package/package.json +39 -22
  2. package/sp-picker.dev.js +3 -0
  3. package/sp-picker.dev.js.map +7 -0
  4. package/sp-picker.js +3 -14
  5. package/sp-picker.js.map +7 -1
  6. package/src/Picker.dev.js +501 -0
  7. package/src/Picker.dev.js.map +7 -0
  8. package/src/Picker.js +405 -434
  9. package/src/Picker.js.map +7 -1
  10. package/src/index.dev.js +2 -0
  11. package/src/index.dev.js.map +7 -0
  12. package/src/index.js +2 -13
  13. package/src/index.js.map +7 -1
  14. package/src/picker.css.dev.js +304 -0
  15. package/src/picker.css.dev.js.map +7 -0
  16. package/src/picker.css.js +17 -38
  17. package/src/picker.css.js.map +7 -1
  18. package/src/spectrum-picker.css.dev.js +300 -0
  19. package/src/spectrum-picker.css.dev.js.map +7 -0
  20. package/src/spectrum-picker.css.js +17 -38
  21. package/src/spectrum-picker.css.js.map +7 -1
  22. package/stories/picker-sizes.stories.js +22 -30
  23. package/stories/picker-sizes.stories.js.map +7 -1
  24. package/stories/picker.stories.js +84 -95
  25. package/stories/picker.stories.js.map +7 -1
  26. package/stories/states.js +225 -236
  27. package/stories/states.js.map +7 -1
  28. package/sync/index.dev.js +8 -0
  29. package/sync/index.dev.js.map +7 -0
  30. package/sync/index.js +6 -15
  31. package/sync/index.js.map +7 -1
  32. package/sync/sp-picker.dev.js +3 -0
  33. package/sync/sp-picker.dev.js.map +7 -0
  34. package/sync/sp-picker.js +3 -14
  35. package/sync/sp-picker.js.map +7 -1
  36. package/test/benchmark/basic-test.js +256 -267
  37. package/test/benchmark/basic-test.js.map +7 -1
  38. package/test/index.js +830 -844
  39. package/test/index.js.map +7 -1
  40. package/test/picker-reparenting.test.js +71 -76
  41. package/test/picker-reparenting.test.js.map +7 -1
  42. package/test/picker-responsive.test.js +41 -53
  43. package/test/picker-responsive.test.js.map +7 -1
  44. package/test/picker-sizes.test-vrt.js +4 -15
  45. package/test/picker-sizes.test-vrt.js.map +7 -1
  46. package/test/picker-sync.test.js +5 -16
  47. package/test/picker-sync.test.js.map +7 -1
  48. package/test/picker.test-vrt.js +4 -15
  49. package/test/picker.test-vrt.js.map +7 -1
  50. package/test/picker.test.js +5 -16
  51. package/test/picker.test.js.map +7 -1
package/test/index.js CHANGED
@@ -1,29 +1,36 @@
1
- /*
2
- Copyright 2020 Adobe. All rights reserved.
3
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License. You may obtain a copy
5
- of the License at http://www.apache.org/licenses/LICENSE-2.0
6
-
7
- Unless required by applicable law or agreed to in writing, software distributed under
8
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- OF ANY KIND, either express or implied. See the License for the specific language
10
- governing permissions and limitations under the License.
11
- */
12
- import { elementUpdated, expect, fixture, html, nextFrame, oneEvent, waitUntil, } from '@open-wc/testing';
13
- import '@spectrum-web-components/shared/src/focus-visible.js';
14
- import { spy } from 'sinon';
15
- import { arrowDownEvent, arrowLeftEvent, arrowRightEvent, arrowUpEvent, tEvent, } from '../../../test/testing-helpers.js';
16
- import { a11ySnapshot, findAccessibilityNode, sendKeys, } from '@web/test-runner-commands';
17
- import { iconsOnly } from '../stories/picker.stories.js';
18
- import { sendMouse } from '../../../test/plugins/browser.js';
19
- const isMenuActiveElement = function () {
20
- var _a;
21
- return ((_a = document.activeElement) === null || _a === void 0 ? void 0 : _a.localName) === 'sp-menu';
1
+ import {
2
+ elementUpdated,
3
+ expect,
4
+ fixture,
5
+ html,
6
+ nextFrame,
7
+ oneEvent,
8
+ waitUntil
9
+ } from "@open-wc/testing";
10
+ import "@spectrum-web-components/shared/src/focus-visible.js";
11
+ import { spy } from "sinon";
12
+ import {
13
+ arrowDownEvent,
14
+ arrowLeftEvent,
15
+ arrowRightEvent,
16
+ arrowUpEvent,
17
+ tEvent
18
+ } from "../../../test/testing-helpers.js";
19
+ import {
20
+ a11ySnapshot,
21
+ findAccessibilityNode,
22
+ sendKeys
23
+ } from "@web/test-runner-commands";
24
+ import { iconsOnly } from "../stories/picker.stories.js";
25
+ import { sendMouse } from "../../../test/plugins/browser.js";
26
+ const isMenuActiveElement = function() {
27
+ var _a;
28
+ return ((_a = document.activeElement) == null ? void 0 : _a.localName) === "sp-menu";
22
29
  };
23
30
  export function runPickerTests() {
24
- let el;
25
- const pickerFixture = async () => {
26
- const test = await fixture(html `
31
+ let el;
32
+ const pickerFixture = async () => {
33
+ const test = await fixture(html`
27
34
  <div>
28
35
  <sp-field-label for="picker">
29
36
  Where do you live?
@@ -44,657 +51,635 @@ export function runPickerTests() {
44
51
  </sp-picker>
45
52
  </div>
46
53
  `);
47
- return test.querySelector('sp-picker');
48
- };
49
- describe('standard', () => {
50
- beforeEach(async () => {
51
- el = await pickerFixture();
52
- await elementUpdated(el);
53
- });
54
- afterEach(async () => {
55
- if (el.open) {
56
- const closed = oneEvent(el, 'sp-closed');
57
- el.open = false;
58
- await closed;
59
- }
60
- });
61
- it('loads accessibly', async () => {
62
- await expect(el).to.be.accessible();
63
- });
64
- it('closes accessibly', async () => {
65
- const opened = oneEvent(el, 'sp-opened');
66
- el.open = true;
67
- await opened;
68
- expect(el.open).to.be.true;
69
- const accessibleCloseButton = document.querySelector('.visually-hidden button');
70
- const closed = oneEvent(el, 'sp-closed');
71
- accessibleCloseButton.click();
72
- await closed;
73
- expect(el.open).to.be.false;
74
- });
75
- it('accepts new selected item content', async () => {
76
- const option2 = el.querySelector('[value="option-2"');
77
- el.value = 'option-2';
78
- await elementUpdated(option2);
79
- await elementUpdated(el);
80
- expect(el.value).to.equal('option-2');
81
- expect((el.button.textContent || '').trim()).to.equal('Select Inverse');
82
- let itemUpdated = oneEvent(el, 'sp-menu-item-added-or-updated');
83
- const newLabel1 = 'Invert Selection';
84
- option2.innerHTML = newLabel1;
85
- await itemUpdated;
86
- await elementUpdated(el);
87
- expect(el.value).to.equal('option-2');
88
- expect((el.button.textContent || '').trim()).to.equal(newLabel1);
89
- itemUpdated = oneEvent(el, 'sp-menu-item-added-or-updated');
90
- const newLabel2 = 'Other option';
91
- option2.childNodes[0].textContent = newLabel2;
92
- await itemUpdated;
93
- await elementUpdated(el);
94
- expect(el.value).to.equal('option-2');
95
- expect((el.button.textContent || '').trim()).to.equal(newLabel2);
96
- });
97
- it('accepts new selected item content when open', async () => {
98
- const option2 = el.querySelector('[value="option-2"');
99
- el.value = 'option-2';
100
- await elementUpdated(el);
101
- expect(el.value).to.equal('option-2');
102
- expect((el.button.textContent || '').trim()).to.equal('Select Inverse');
103
- const opened = oneEvent(el, 'sp-opened');
104
- el.open = true;
105
- await opened;
106
- const itemUpdated = oneEvent(option2, 'sp-menu-item-added-or-updated');
107
- option2.innerHTML = 'Invert Selection';
108
- await itemUpdated;
109
- await elementUpdated(el);
110
- expect(el.value).to.equal('option-2');
111
- expect((el.button.textContent || '').trim()).to.equal('Invert Selection');
112
- });
113
- it('unsets value when children removed', async () => {
114
- el.value = 'option-2';
115
- await elementUpdated(el);
116
- expect(el.value).to.equal('option-2');
117
- expect((el.button.textContent || '').trim()).to.equal('Select Inverse');
118
- const items = el.querySelectorAll('sp-menu-item');
119
- const removals = [];
120
- items.forEach((item) => {
121
- const removal = oneEvent(el, 'sp-menu-item-removed');
122
- item.remove();
123
- removals.push(removal);
124
- });
125
- await Promise.all(removals);
126
- await elementUpdated(el);
127
- expect(el.value).to.equal('');
128
- expect((el.button.textContent || '').trim()).to.equal('');
129
- });
130
- it('accepts a new item and value at the same time', async () => {
131
- el.value = 'option-2';
132
- await elementUpdated(el);
133
- expect(el.value).to.equal('option-2');
134
- const item = document.createElement('sp-menu-item');
135
- item.value = 'option-new';
136
- item.textContent = 'New Option';
137
- el.append(item);
138
- await elementUpdated(el);
139
- el.value = 'option-new';
140
- await elementUpdated(el);
141
- expect(el.value).to.equal('option-new');
142
- });
143
- it('accepts a new item that can be selected', async () => {
144
- el.value = 'option-2';
145
- await elementUpdated(el);
146
- expect(el.value).to.equal('option-2');
147
- const item = document.createElement('sp-menu-item');
148
- item.value = 'option-new';
149
- item.textContent = 'New Option';
150
- el.append(item);
151
- await elementUpdated(item);
152
- await elementUpdated(el);
153
- let opened = oneEvent(el, 'sp-opened');
154
- el.open = true;
155
- await opened;
156
- // Overlaid content is outside of the context of the Picker element
157
- // and cannot be managed via its updateComplete cycle.
158
- await nextFrame();
159
- const close = oneEvent(el, 'sp-closed');
160
- item.click();
161
- await close;
162
- // Overlaid content is outside of the context of the Picker element
163
- // and cannot be managed via its updateComplete cycle.
164
- await nextFrame();
165
- expect(el.value, 'first time').to.equal('option-new');
166
- opened = oneEvent(el, 'sp-opened');
167
- el.open = true;
168
- await opened;
169
- // Overlaid content is outside of the context of the Picker element
170
- // and cannot be managed via its updateComplete cycle.
171
- await nextFrame();
172
- expect(el.value, 'second time').to.equal('option-new');
173
- });
174
- it('manages its "name" value in the accessibility tree', async () => {
175
- let snapshot = (await a11ySnapshot({}));
176
- expect(findAccessibilityNode(snapshot, (node) => node.name === 'Where do you live?'), '`name` is the label text').to.not.be.null;
177
- el.value = 'option-2';
178
- await elementUpdated(el);
179
- snapshot = (await a11ySnapshot({}));
180
- expect(findAccessibilityNode(snapshot, (node) => node.name === 'Where do you live? Select Inverse'), '`name` is the label text plus the selected item text').to.not.be.null;
181
- });
182
- it('manages `aria-activedescendant`', async () => {
183
- const firstItem = el.querySelector('sp-menu-item:nth-child(1)');
184
- const secondItem = el.querySelector('sp-menu-item:nth-child(2)');
185
- const opened = oneEvent(el, 'sp-opened');
186
- el.open = true;
187
- await opened;
188
- expect(el.optionsMenu.getAttribute('aria-activedescendant')).to.equal(firstItem === null || firstItem === void 0 ? void 0 : firstItem.id);
189
- await sendKeys({ press: 'ArrowDown' });
190
- await elementUpdated(el);
191
- expect(el.optionsMenu.getAttribute('aria-activedescendant')).to.equal(secondItem === null || secondItem === void 0 ? void 0 : secondItem.id);
192
- });
193
- it('renders invalid accessibly', async () => {
194
- el.invalid = true;
195
- await elementUpdated(el);
196
- expect(el.invalid).to.be.true;
197
- await expect(el).to.be.accessible();
198
- });
199
- it('renders selection accessibly', async () => {
200
- el.value = 'option-2';
201
- await elementUpdated(el);
202
- await expect(el).to.be.accessible();
203
- });
204
- it('opens with visible focus on a menu item on `DownArrow`', async () => {
205
- const firstItem = el.querySelector('sp-menu-item');
206
- await elementUpdated(el);
207
- expect(firstItem.focused, 'should not visually focused').to.be
208
- .false;
209
- el.focus();
210
- await elementUpdated(el);
211
- const opened = oneEvent(el, 'sp-opened');
212
- await sendKeys({ press: 'ArrowRight' });
213
- await sendKeys({ press: 'ArrowLeft' });
214
- await sendKeys({ press: 'ArrowDown' });
215
- await opened;
216
- expect(el.open).to.be.true;
217
- expect(firstItem.focused, 'should be visually focused').to.be.true;
218
- const closed = oneEvent(el, 'sp-closed');
219
- await sendKeys({
220
- press: 'Escape',
221
- });
222
- await closed;
223
- expect(el.open).to.be.false;
224
- await waitUntil(() => !firstItem.focused, 'not visually focused');
225
- });
226
- it('opens without visible focus on a menu item on click', async () => {
227
- const firstItem = el.querySelector('sp-menu-item');
228
- await elementUpdated(el);
229
- const boundingRect = el.getBoundingClientRect();
230
- expect(firstItem.focused, 'not visually focused').to.be.false;
231
- const opened = oneEvent(el, 'sp-opened');
232
- sendMouse({
233
- steps: [
234
- {
235
- type: 'click',
236
- position: [
237
- boundingRect.x + boundingRect.width / 2,
238
- boundingRect.y + boundingRect.height / 2,
239
- ],
240
- },
241
- ],
242
- });
243
- await opened;
244
- await elementUpdated(el);
245
- expect(el.open).to.be.true;
246
- expect(firstItem.focused, 'still not visually focused').to.be.false;
247
- });
248
- it('closes when becoming disabled', async () => {
249
- expect(el.open).to.be.false;
250
- el.click();
251
- await elementUpdated(el);
252
- expect(el.open).to.be.true;
253
- el.disabled = true;
254
- await elementUpdated(el);
255
- expect(el.open).to.be.false;
256
- });
257
- it('closes when clicking away', async () => {
258
- el.id = 'closing';
259
- const other = document.createElement('div');
260
- document.body.append(other);
261
- await elementUpdated(el);
262
- expect(el.open).to.be.false;
263
- el.click();
264
- await elementUpdated(el);
265
- expect(el.open).to.be.true;
266
- other.click();
267
- await waitUntil(() => !el.open, 'closed');
268
- other.remove();
269
- });
270
- it('selects', async () => {
271
- var _a, _b;
272
- const secondItem = el.querySelector('sp-menu-item:nth-of-type(2)');
273
- const button = el.button;
274
- const opened = oneEvent(el, 'sp-opened');
275
- button.click();
276
- await opened;
277
- await elementUpdated(el);
278
- expect(el.open).to.be.true;
279
- expect((_a = el.selectedItem) === null || _a === void 0 ? void 0 : _a.itemText).to.be.undefined;
280
- expect(el.value).to.equal('');
281
- const closed = oneEvent(el, 'sp-closed');
282
- secondItem.click();
283
- await closed;
284
- expect(el.open).to.be.false;
285
- expect((_b = el.selectedItem) === null || _b === void 0 ? void 0 : _b.itemText).to.equal('Select Inverse');
286
- expect(el.value).to.equal('option-2');
287
- });
288
- it('re-selects', async () => {
289
- var _a, _b, _c, _d;
290
- const firstItem = el.querySelector('sp-menu-item:nth-of-type(1)');
291
- const secondItem = el.querySelector('sp-menu-item:nth-of-type(2)');
292
- const button = el.button;
293
- const opened = oneEvent(el, 'sp-opened');
294
- button.click();
295
- await opened;
296
- await nextFrame();
297
- expect(el.open).to.be.true;
298
- expect((_a = el.selectedItem) === null || _a === void 0 ? void 0 : _a.itemText).to.be.undefined;
299
- expect(el.value).to.equal('');
300
- const closed = oneEvent(el, 'sp-closed');
301
- secondItem.click();
302
- await closed;
303
- await nextFrame();
304
- expect(el.open).to.be.false;
305
- expect((_b = el.selectedItem) === null || _b === void 0 ? void 0 : _b.itemText).to.equal('Select Inverse');
306
- expect(el.value).to.equal('option-2');
307
- const opened2 = oneEvent(el, 'sp-opened');
308
- button.click();
309
- await opened2;
310
- await nextFrame();
311
- expect(el.open).to.be.true;
312
- expect((_c = el.selectedItem) === null || _c === void 0 ? void 0 : _c.itemText).to.equal('Select Inverse');
313
- expect(el.value).to.equal('option-2');
314
- const closed2 = oneEvent(el, 'sp-closed');
315
- firstItem.click();
316
- await closed2;
317
- await nextFrame();
318
- expect(el.open).to.be.false;
319
- expect((_d = el.selectedItem) === null || _d === void 0 ? void 0 : _d.itemText).to.equal('Deselect');
320
- expect(el.value).to.equal('Deselect');
321
- });
322
- it('dispatches bubbling and composed events', async () => {
323
- const changeSpy = spy();
324
- const parent = el.parentElement;
325
- parent.attachShadow({ mode: 'open' });
326
- parent.shadowRoot.append(el);
327
- const secondItem = el.querySelector('sp-menu-item:nth-of-type(2)');
328
- parent.addEventListener('change', () => changeSpy());
329
- expect(el.value).to.equal('');
330
- const opened = oneEvent(el, 'sp-opened');
331
- el.open = true;
332
- await opened;
333
- await elementUpdated(el);
334
- const closed = oneEvent(el, 'sp-closed');
335
- secondItem.click();
336
- await closed;
337
- await elementUpdated(el);
338
- expect(el.value).to.equal(secondItem.value);
339
- expect(changeSpy.calledOnce).to.be.true;
340
- });
341
- it('can have selection prevented', async () => {
342
- var _a;
343
- const preventChangeSpy = spy();
344
- const secondItem = el.querySelector('sp-menu-item:nth-of-type(2)');
345
- const button = el.button;
346
- let opened = oneEvent(el, 'sp-opened');
347
- button.click();
348
- await opened;
349
- await elementUpdated(el);
350
- expect(el.open).to.be.true;
351
- expect((_a = el.selectedItem) === null || _a === void 0 ? void 0 : _a.itemText).to.be.undefined;
352
- expect(el.value).to.equal('');
353
- expect(secondItem.selected).to.be.false;
354
- el.addEventListener('change', (event) => {
355
- event.preventDefault();
356
- preventChangeSpy();
357
- });
358
- const closed = oneEvent(el, 'sp-closed');
359
- opened = oneEvent(el, 'sp-opened');
360
- secondItem.click();
361
- await closed;
362
- await opened;
363
- await elementUpdated(el);
364
- expect(preventChangeSpy.calledOnce).to.be.true;
365
- expect(secondItem.selected, 'selection prevented').to.be.false;
366
- });
367
- it('can throw focus after `change`', async () => {
368
- var _a;
369
- const input = document.createElement('input');
370
- document.body.append(input);
371
- await elementUpdated(el);
372
- const secondItem = el.querySelector('sp-menu-item:nth-of-type(2)');
373
- const button = el.button;
374
- const opened = oneEvent(el, 'sp-opened');
375
- button.click();
376
- await opened;
377
- await elementUpdated(el);
378
- expect(el.open).to.be.true;
379
- expect((_a = el.selectedItem) === null || _a === void 0 ? void 0 : _a.itemText).to.be.undefined;
380
- expect(el.value).to.equal('');
381
- expect(secondItem.selected).to.be.false;
382
- el.addEventListener('change', () => {
383
- input.focus();
384
- });
385
- const closed = oneEvent(el, 'sp-closed');
386
- secondItem.click();
387
- await closed;
388
- await elementUpdated(el);
389
- expect(el.open).to.be.false;
390
- expect(el.value, 'value changed').to.equal('option-2');
391
- expect(secondItem.selected, 'selected changed').to.be.true;
392
- await waitUntil(() => document.activeElement === input, 'focus throw');
393
- input.remove();
394
- });
395
- it('opens on ArrowUp', async () => {
396
- const button = el.button;
397
- el.focus();
398
- await elementUpdated(el);
399
- expect(el.open, 'inially closed').to.be.false;
400
- button.dispatchEvent(tEvent());
401
- await elementUpdated(el);
402
- expect(el.open, 'still closed').to.be.false;
403
- button.dispatchEvent(arrowUpEvent());
404
- await elementUpdated(el);
405
- expect(el.open, 'open by ArrowUp').to.be.true;
406
- await waitUntil(() => document.querySelector('active-overlay') !== null, 'an active-overlay has been inserted on the page');
407
- button.dispatchEvent(new KeyboardEvent('keyup', {
408
- bubbles: true,
409
- composed: true,
410
- cancelable: true,
411
- key: 'Escape',
412
- code: 'Escape',
413
- }));
414
- await elementUpdated(el);
415
- await waitUntil(() => el.open === false, 'closed by Escape');
416
- await waitUntil(() => document.querySelector('active-overlay') === null, 'an active-overlay has been inserted on the page');
417
- });
418
- it('opens on ArrowDown', async () => {
419
- var _a, _b;
420
- const firstItem = el.querySelector('sp-menu-item:nth-of-type(1)');
421
- const button = el.button;
422
- el.focus();
423
- await elementUpdated(el);
424
- expect(el.open, 'inially closed').to.be.false;
425
- const opened = oneEvent(el, 'sp-opened');
426
- button.dispatchEvent(arrowDownEvent());
427
- await opened;
428
- await elementUpdated(el);
429
- expect(el.open, 'open by ArrowDown').to.be.true;
430
- expect((_a = el.selectedItem) === null || _a === void 0 ? void 0 : _a.itemText).to.be.undefined;
431
- expect(el.value).to.equal('');
432
- const closed = oneEvent(el, 'sp-closed');
433
- firstItem.click();
434
- await closed;
435
- await elementUpdated(el);
436
- expect(el.open).to.be.false;
437
- expect((_b = el.selectedItem) === null || _b === void 0 ? void 0 : _b.itemText).to.equal('Deselect');
438
- expect(el.value).to.equal('Deselect');
439
- });
440
- it('quick selects on ArrowLeft/Right', async () => {
441
- const selectionSpy = spy();
442
- el.addEventListener('change', (event) => {
443
- const { value } = event.target;
444
- selectionSpy(value);
445
- });
446
- const button = el.button;
447
- el.focus();
448
- button.dispatchEvent(arrowLeftEvent());
449
- await elementUpdated(el);
450
- expect(selectionSpy.callCount).to.equal(1);
451
- expect(selectionSpy.calledWith('Deselected'));
452
- button.dispatchEvent(arrowLeftEvent());
453
- await elementUpdated(el);
454
- expect(selectionSpy.callCount).to.equal(1);
455
- button.dispatchEvent(arrowRightEvent());
456
- await elementUpdated(el);
457
- expect(selectionSpy.calledWith('option-2'));
458
- button.dispatchEvent(arrowRightEvent());
459
- button.dispatchEvent(arrowRightEvent());
460
- button.dispatchEvent(arrowRightEvent());
461
- button.dispatchEvent(arrowRightEvent());
462
- await elementUpdated(el);
463
- expect(selectionSpy.callCount).to.equal(5);
464
- expect(selectionSpy.calledWith('Save Selection'));
465
- expect(selectionSpy.calledWith('Make Work Path')).to.be.false;
466
- });
467
- it('quick selects first item on ArrowRight when no value', async () => {
468
- const selectionSpy = spy();
469
- el.addEventListener('change', (event) => {
470
- const { value } = event.target;
471
- selectionSpy(value);
472
- });
473
- const button = el.button;
474
- el.focus();
475
- button.dispatchEvent(arrowRightEvent());
476
- await elementUpdated(el);
477
- expect(selectionSpy.callCount).to.equal(1);
478
- expect(selectionSpy.calledWith('Deselected'));
479
- });
480
- it('loads', async () => {
481
- expect(el).to.not.be.undefined;
482
- });
483
- it('refocuses on list when open', async () => {
484
- const firstItem = el.querySelector('sp-menu-item');
485
- const input = document.createElement('input');
486
- el.insertAdjacentElement('afterend', input);
487
- el.focus();
488
- await sendKeys({ press: 'Tab' });
489
- expect(document.activeElement === input).to.be.true;
490
- await sendKeys({ press: 'Shift+Tab' });
491
- expect(document.activeElement === el).to.be.true;
492
- await sendKeys({ press: 'Enter' });
493
- const opened = oneEvent(el, 'sp-opened');
494
- el.open = true;
495
- await opened;
496
- await elementUpdated(el);
497
- await waitUntil(() => firstItem.focused, 'The first items should have become focused visually.');
498
- el.blur();
499
- await elementUpdated(el);
500
- expect(el.open).to.be.true;
501
- el.focus();
502
- await elementUpdated(el);
503
- await waitUntil(() => isMenuActiveElement(), 'first item refocused');
504
- expect(el.open).to.be.true;
505
- expect(isMenuActiveElement()).to.be.true;
506
- // Force :focus-visible heuristic
507
- await sendKeys({ press: 'ArrowDown' });
508
- await sendKeys({ press: 'ArrowUp' });
509
- expect(firstItem.focused).to.be.true;
510
- });
511
- it('does not allow tabing to close', async () => {
512
- el.open = true;
513
- await elementUpdated(el);
514
- expect(el.open).to.be.true;
515
- el.focus();
516
- await elementUpdated(el);
517
- await waitUntil(() => isMenuActiveElement(), 'first item refocused');
518
- expect(el.open).to.be.true;
519
- expect(isMenuActiveElement()).to.be.true;
520
- await sendKeys({ press: 'Tab' });
521
- expect(el.open, 'stays open').to.be.true;
522
- });
523
- describe('tab order', () => {
524
- let input1;
525
- let input2;
526
- beforeEach(() => {
527
- const surroundingInput = () => {
528
- const input = document.createElement('input');
529
- input.type = 'text';
530
- input.tabIndex = 0;
531
- return input;
532
- };
533
- input1 = surroundingInput();
534
- input2 = surroundingInput();
535
- el.insertAdjacentElement('beforebegin', input1);
536
- el.insertAdjacentElement('afterend', input2);
537
- });
538
- afterEach(() => {
539
- input1.remove();
540
- input2.remove();
541
- });
542
- it('tabs forward through the element', async () => {
543
- // start at input1
544
- input1.focus();
545
- await nextFrame();
546
- expect(document.activeElement === input1, 'focuses input 1').to
547
- .true;
548
- // tab to the picker
549
- let focused = oneEvent(el, 'focus');
550
- await sendKeys({ press: 'Tab' });
551
- await focused;
552
- expect(el.focused, 'focused').to.be.true;
553
- expect(el.open, 'closed').to.be.false;
554
- expect(document.activeElement === el, 'focuses el').to.be.true;
555
- // tab through the picker to input2
556
- focused = oneEvent(input2, 'focus');
557
- await sendKeys({ press: 'Tab' });
558
- await focused;
559
- expect(document.activeElement === input2, 'focuses input 2').to
560
- .true;
561
- });
562
- it('shift+tabs backwards through the element', async () => {
563
- // start at input1
564
- input2.focus();
565
- await nextFrame();
566
- expect(document.activeElement, 'focuses input 2').to.equal(input2);
567
- // tab to the picker
568
- let focused = oneEvent(el, 'focus');
569
- await sendKeys({ press: 'Shift+Tab' });
570
- await focused;
571
- expect(el.focused, 'focused').to.be.true;
572
- expect(el.open, 'closed').to.be.false;
573
- expect(document.activeElement, 'focuses el').to.equal(el);
574
- // tab through the picker to input2
575
- focused = oneEvent(input1, 'focus');
576
- await sendKeys({ press: 'Shift+Tab' });
577
- await focused;
578
- expect(document.activeElement, 'focuses input 1').to.equal(input1);
579
- });
580
- it('traps tab in the menu as a `type="modal"` overlay forward', async () => {
581
- el.focus();
582
- await nextFrame();
583
- expect(document.activeElement, 'focuses el').to.equal(el);
584
- // press down to open the picker
585
- const opened = oneEvent(el, 'sp-opened');
586
- await sendKeys({ press: 'ArrowDown' });
587
- await opened;
588
- expect(el.open, 'opened').to.be.true;
589
- await waitUntil(() => isMenuActiveElement(), 'first item focused');
590
- const activeElement = document.activeElement;
591
- const blured = oneEvent(activeElement, 'blur');
592
- await sendKeys({ press: 'Tab' });
593
- await blured;
594
- expect(el.open).to.be.true;
595
- expect(document.activeElement === input1).to.be.false;
596
- expect(document.activeElement === input2).to.be.false;
597
- });
598
- it('traps tab in the menu as a `type="modal"` overlay backwards', async () => {
599
- el.focus();
600
- await nextFrame();
601
- expect(document.activeElement, 'focuses el').to.equal(el);
602
- // press down to open the picker
603
- const opened = oneEvent(el, 'sp-opened');
604
- await sendKeys({ press: 'ArrowDown' });
605
- await opened;
606
- expect(el.open, 'opened').to.be.true;
607
- await waitUntil(() => isMenuActiveElement(), 'first item focused');
608
- const activeElement = document.activeElement;
609
- const blured = oneEvent(activeElement, 'blur');
610
- await sendKeys({ press: 'Shift+Tab' });
611
- await blured;
612
- expect(el.open).to.be.true;
613
- expect(document.activeElement === input1).to.be.false;
614
- expect(document.activeElement === input2).to.be.false;
615
- });
616
- it('can close and immediate tab to the next tab stop', async () => {
617
- el.focus();
618
- await nextFrame();
619
- expect(document.activeElement, 'focuses el').to.equal(el);
620
- // press down to open the picker
621
- const opened = oneEvent(el, 'sp-opened');
622
- await sendKeys({ press: 'ArrowUp' });
623
- await opened;
624
- expect(el.open, 'opened').to.be.true;
625
- await waitUntil(() => isMenuActiveElement(), 'first item focused');
626
- const closed = oneEvent(el, 'sp-closed');
627
- el.open = false;
628
- await closed;
629
- expect(el.open).to.be.false;
630
- expect(document.activeElement === el).to.be.true;
631
- const focused = oneEvent(input2, 'focus');
632
- await sendKeys({ press: 'Tab' });
633
- await focused;
634
- expect(el.open).to.be.false;
635
- expect(document.activeElement === input2).to.be.true;
636
- });
637
- it('can close and immediate shift+tab to the previous tab stop', async () => {
638
- el.focus();
639
- await nextFrame();
640
- expect(document.activeElement, 'focuses el').to.equal(el);
641
- // press down to open the picker
642
- const opened = oneEvent(el, 'sp-opened');
643
- await sendKeys({ press: 'ArrowUp' });
644
- await opened;
645
- expect(el.open, 'opened').to.be.true;
646
- await waitUntil(() => isMenuActiveElement(), 'first item focused');
647
- const closed = oneEvent(el, 'sp-closed');
648
- el.open = false;
649
- await closed;
650
- expect(el.open).to.be.false;
651
- expect(document.activeElement === el).to.be.true;
652
- const focused = oneEvent(input1, 'focus');
653
- await sendKeys({ press: 'Shift+Tab' });
654
- await focused;
655
- expect(el.open).to.be.false;
656
- expect(document.activeElement === input1).to.be.true;
657
- });
658
- });
659
- it('does not open when [readonly]', async () => {
660
- el.readonly = true;
661
- await elementUpdated(el);
662
- const button = el.button;
663
- button.click();
664
- await elementUpdated(el);
665
- expect(el.open).to.be.false;
666
- });
667
- it('scrolls selected into view on open', async () => {
668
- await el.generatePopover();
669
- el.popover.style.height =
670
- '40px';
671
- const firstItem = el.querySelector('sp-menu-item:first-child');
672
- const lastItem = el.querySelector('sp-menu-item:last-child');
673
- lastItem.disabled = false;
674
- el.value = lastItem.value;
675
- await elementUpdated(el);
676
- el.open = true;
677
- await elementUpdated(el);
678
- await waitUntil(() => isMenuActiveElement(), 'first item focused');
679
- const getParentOffset = (el) => {
680
- const parentScroll = el.parentElement
681
- .scrollTop;
682
- const parentOffset = el.offsetTop - parentScroll;
683
- return parentOffset;
684
- };
685
- expect(getParentOffset(lastItem)).to.be.lessThan(40);
686
- expect(getParentOffset(firstItem)).to.be.lessThan(-1);
687
- lastItem.dispatchEvent(new FocusEvent('focusin', { bubbles: true }));
688
- lastItem.dispatchEvent(arrowDownEvent());
689
- await elementUpdated(el);
690
- await nextFrame();
691
- expect(getParentOffset(lastItem)).to.be.greaterThan(40);
692
- expect(getParentOffset(firstItem)).to.be.greaterThan(-1);
693
- });
694
- });
695
- describe('slotted label', () => {
696
- const pickerFixture = async () => {
697
- const test = await fixture(html `
54
+ return test.querySelector("sp-picker");
55
+ };
56
+ describe("standard", () => {
57
+ beforeEach(async () => {
58
+ el = await pickerFixture();
59
+ await elementUpdated(el);
60
+ });
61
+ afterEach(async () => {
62
+ if (el.open) {
63
+ const closed = oneEvent(el, "sp-closed");
64
+ el.open = false;
65
+ await closed;
66
+ }
67
+ });
68
+ it("loads accessibly", async () => {
69
+ await expect(el).to.be.accessible();
70
+ });
71
+ it("closes accessibly", async () => {
72
+ const opened = oneEvent(el, "sp-opened");
73
+ el.open = true;
74
+ await opened;
75
+ expect(el.open).to.be.true;
76
+ const accessibleCloseButton = document.querySelector(".visually-hidden button");
77
+ const closed = oneEvent(el, "sp-closed");
78
+ accessibleCloseButton.click();
79
+ await closed;
80
+ expect(el.open).to.be.false;
81
+ });
82
+ it("accepts new selected item content", async () => {
83
+ const option2 = el.querySelector('[value="option-2"');
84
+ el.value = "option-2";
85
+ await elementUpdated(option2);
86
+ await elementUpdated(el);
87
+ expect(el.value).to.equal("option-2");
88
+ expect((el.button.textContent || "").trim()).to.equal("Select Inverse");
89
+ let itemUpdated = oneEvent(el, "sp-menu-item-added-or-updated");
90
+ const newLabel1 = "Invert Selection";
91
+ option2.innerHTML = newLabel1;
92
+ await itemUpdated;
93
+ await elementUpdated(el);
94
+ expect(el.value).to.equal("option-2");
95
+ expect((el.button.textContent || "").trim()).to.equal(newLabel1);
96
+ itemUpdated = oneEvent(el, "sp-menu-item-added-or-updated");
97
+ const newLabel2 = "Other option";
98
+ option2.childNodes[0].textContent = newLabel2;
99
+ await itemUpdated;
100
+ await elementUpdated(el);
101
+ expect(el.value).to.equal("option-2");
102
+ expect((el.button.textContent || "").trim()).to.equal(newLabel2);
103
+ });
104
+ it("accepts new selected item content when open", async () => {
105
+ const option2 = el.querySelector('[value="option-2"');
106
+ el.value = "option-2";
107
+ await elementUpdated(el);
108
+ expect(el.value).to.equal("option-2");
109
+ expect((el.button.textContent || "").trim()).to.equal("Select Inverse");
110
+ const opened = oneEvent(el, "sp-opened");
111
+ el.open = true;
112
+ await opened;
113
+ const itemUpdated = oneEvent(option2, "sp-menu-item-added-or-updated");
114
+ option2.innerHTML = "Invert Selection";
115
+ await itemUpdated;
116
+ await elementUpdated(el);
117
+ expect(el.value).to.equal("option-2");
118
+ expect((el.button.textContent || "").trim()).to.equal("Invert Selection");
119
+ });
120
+ it("unsets value when children removed", async () => {
121
+ el.value = "option-2";
122
+ await elementUpdated(el);
123
+ expect(el.value).to.equal("option-2");
124
+ expect((el.button.textContent || "").trim()).to.equal("Select Inverse");
125
+ const items = el.querySelectorAll("sp-menu-item");
126
+ const removals = [];
127
+ items.forEach((item) => {
128
+ const removal = oneEvent(el, "sp-menu-item-removed");
129
+ item.remove();
130
+ removals.push(removal);
131
+ });
132
+ await Promise.all(removals);
133
+ await elementUpdated(el);
134
+ expect(el.value).to.equal("");
135
+ expect((el.button.textContent || "").trim()).to.equal("");
136
+ });
137
+ it("accepts a new item and value at the same time", async () => {
138
+ el.value = "option-2";
139
+ await elementUpdated(el);
140
+ expect(el.value).to.equal("option-2");
141
+ const item = document.createElement("sp-menu-item");
142
+ item.value = "option-new";
143
+ item.textContent = "New Option";
144
+ el.append(item);
145
+ await elementUpdated(el);
146
+ el.value = "option-new";
147
+ await elementUpdated(el);
148
+ expect(el.value).to.equal("option-new");
149
+ });
150
+ it("accepts a new item that can be selected", async () => {
151
+ el.value = "option-2";
152
+ await elementUpdated(el);
153
+ expect(el.value).to.equal("option-2");
154
+ const item = document.createElement("sp-menu-item");
155
+ item.value = "option-new";
156
+ item.textContent = "New Option";
157
+ el.append(item);
158
+ await elementUpdated(item);
159
+ await elementUpdated(el);
160
+ let opened = oneEvent(el, "sp-opened");
161
+ el.open = true;
162
+ await opened;
163
+ await nextFrame();
164
+ const close = oneEvent(el, "sp-closed");
165
+ item.click();
166
+ await close;
167
+ await nextFrame();
168
+ expect(el.value, "first time").to.equal("option-new");
169
+ opened = oneEvent(el, "sp-opened");
170
+ el.open = true;
171
+ await opened;
172
+ await nextFrame();
173
+ expect(el.value, "second time").to.equal("option-new");
174
+ });
175
+ it('manages its "name" value in the accessibility tree', async () => {
176
+ let snapshot = await a11ySnapshot({});
177
+ expect(findAccessibilityNode(snapshot, (node) => node.name === "Where do you live?"), "`name` is the label text").to.not.be.null;
178
+ el.value = "option-2";
179
+ await elementUpdated(el);
180
+ snapshot = await a11ySnapshot({});
181
+ expect(findAccessibilityNode(snapshot, (node) => node.name === "Where do you live? Select Inverse"), "`name` is the label text plus the selected item text").to.not.be.null;
182
+ });
183
+ it("manages `aria-activedescendant`", async () => {
184
+ const firstItem = el.querySelector("sp-menu-item:nth-child(1)");
185
+ const secondItem = el.querySelector("sp-menu-item:nth-child(2)");
186
+ const opened = oneEvent(el, "sp-opened");
187
+ el.open = true;
188
+ await opened;
189
+ expect(el.optionsMenu.getAttribute("aria-activedescendant")).to.equal(firstItem == null ? void 0 : firstItem.id);
190
+ await sendKeys({ press: "ArrowDown" });
191
+ await elementUpdated(el);
192
+ expect(el.optionsMenu.getAttribute("aria-activedescendant")).to.equal(secondItem == null ? void 0 : secondItem.id);
193
+ });
194
+ it("renders invalid accessibly", async () => {
195
+ el.invalid = true;
196
+ await elementUpdated(el);
197
+ expect(el.invalid).to.be.true;
198
+ await expect(el).to.be.accessible();
199
+ });
200
+ it("renders selection accessibly", async () => {
201
+ el.value = "option-2";
202
+ await elementUpdated(el);
203
+ await expect(el).to.be.accessible();
204
+ });
205
+ it("opens with visible focus on a menu item on `DownArrow`", async () => {
206
+ const firstItem = el.querySelector("sp-menu-item");
207
+ await elementUpdated(el);
208
+ expect(firstItem.focused, "should not visually focused").to.be.false;
209
+ el.focus();
210
+ await elementUpdated(el);
211
+ const opened = oneEvent(el, "sp-opened");
212
+ await sendKeys({ press: "ArrowRight" });
213
+ await sendKeys({ press: "ArrowLeft" });
214
+ await sendKeys({ press: "ArrowDown" });
215
+ await opened;
216
+ expect(el.open).to.be.true;
217
+ expect(firstItem.focused, "should be visually focused").to.be.true;
218
+ const closed = oneEvent(el, "sp-closed");
219
+ await sendKeys({
220
+ press: "Escape"
221
+ });
222
+ await closed;
223
+ expect(el.open).to.be.false;
224
+ await waitUntil(() => !firstItem.focused, "not visually focused");
225
+ });
226
+ it("opens without visible focus on a menu item on click", async () => {
227
+ const firstItem = el.querySelector("sp-menu-item");
228
+ await elementUpdated(el);
229
+ const boundingRect = el.getBoundingClientRect();
230
+ expect(firstItem.focused, "not visually focused").to.be.false;
231
+ const opened = oneEvent(el, "sp-opened");
232
+ sendMouse({
233
+ steps: [
234
+ {
235
+ type: "click",
236
+ position: [
237
+ boundingRect.x + boundingRect.width / 2,
238
+ boundingRect.y + boundingRect.height / 2
239
+ ]
240
+ }
241
+ ]
242
+ });
243
+ await opened;
244
+ await elementUpdated(el);
245
+ expect(el.open).to.be.true;
246
+ expect(firstItem.focused, "still not visually focused").to.be.false;
247
+ });
248
+ it("closes when becoming disabled", async () => {
249
+ expect(el.open).to.be.false;
250
+ el.click();
251
+ await elementUpdated(el);
252
+ expect(el.open).to.be.true;
253
+ el.disabled = true;
254
+ await elementUpdated(el);
255
+ expect(el.open).to.be.false;
256
+ });
257
+ it("closes when clicking away", async () => {
258
+ el.id = "closing";
259
+ const other = document.createElement("div");
260
+ document.body.append(other);
261
+ await elementUpdated(el);
262
+ expect(el.open).to.be.false;
263
+ el.click();
264
+ await elementUpdated(el);
265
+ expect(el.open).to.be.true;
266
+ other.click();
267
+ await waitUntil(() => !el.open, "closed");
268
+ other.remove();
269
+ });
270
+ it("selects", async () => {
271
+ var _a, _b;
272
+ const secondItem = el.querySelector("sp-menu-item:nth-of-type(2)");
273
+ const button = el.button;
274
+ const opened = oneEvent(el, "sp-opened");
275
+ button.click();
276
+ await opened;
277
+ await elementUpdated(el);
278
+ expect(el.open).to.be.true;
279
+ expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
280
+ expect(el.value).to.equal("");
281
+ const closed = oneEvent(el, "sp-closed");
282
+ secondItem.click();
283
+ await closed;
284
+ expect(el.open).to.be.false;
285
+ expect((_b = el.selectedItem) == null ? void 0 : _b.itemText).to.equal("Select Inverse");
286
+ expect(el.value).to.equal("option-2");
287
+ });
288
+ it("re-selects", async () => {
289
+ var _a, _b, _c, _d;
290
+ const firstItem = el.querySelector("sp-menu-item:nth-of-type(1)");
291
+ const secondItem = el.querySelector("sp-menu-item:nth-of-type(2)");
292
+ const button = el.button;
293
+ const opened = oneEvent(el, "sp-opened");
294
+ button.click();
295
+ await opened;
296
+ await nextFrame();
297
+ expect(el.open).to.be.true;
298
+ expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
299
+ expect(el.value).to.equal("");
300
+ const closed = oneEvent(el, "sp-closed");
301
+ secondItem.click();
302
+ await closed;
303
+ await nextFrame();
304
+ expect(el.open).to.be.false;
305
+ expect((_b = el.selectedItem) == null ? void 0 : _b.itemText).to.equal("Select Inverse");
306
+ expect(el.value).to.equal("option-2");
307
+ const opened2 = oneEvent(el, "sp-opened");
308
+ button.click();
309
+ await opened2;
310
+ await nextFrame();
311
+ expect(el.open).to.be.true;
312
+ expect((_c = el.selectedItem) == null ? void 0 : _c.itemText).to.equal("Select Inverse");
313
+ expect(el.value).to.equal("option-2");
314
+ const closed2 = oneEvent(el, "sp-closed");
315
+ firstItem.click();
316
+ await closed2;
317
+ await nextFrame();
318
+ expect(el.open).to.be.false;
319
+ expect((_d = el.selectedItem) == null ? void 0 : _d.itemText).to.equal("Deselect");
320
+ expect(el.value).to.equal("Deselect");
321
+ });
322
+ it("dispatches bubbling and composed events", async () => {
323
+ const changeSpy = spy();
324
+ const parent = el.parentElement;
325
+ parent.attachShadow({ mode: "open" });
326
+ parent.shadowRoot.append(el);
327
+ const secondItem = el.querySelector("sp-menu-item:nth-of-type(2)");
328
+ parent.addEventListener("change", () => changeSpy());
329
+ expect(el.value).to.equal("");
330
+ const opened = oneEvent(el, "sp-opened");
331
+ el.open = true;
332
+ await opened;
333
+ await elementUpdated(el);
334
+ const closed = oneEvent(el, "sp-closed");
335
+ secondItem.click();
336
+ await closed;
337
+ await elementUpdated(el);
338
+ expect(el.value).to.equal(secondItem.value);
339
+ expect(changeSpy.calledOnce).to.be.true;
340
+ });
341
+ it("can have selection prevented", async () => {
342
+ var _a;
343
+ const preventChangeSpy = spy();
344
+ const secondItem = el.querySelector("sp-menu-item:nth-of-type(2)");
345
+ const button = el.button;
346
+ let opened = oneEvent(el, "sp-opened");
347
+ button.click();
348
+ await opened;
349
+ await elementUpdated(el);
350
+ expect(el.open).to.be.true;
351
+ expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
352
+ expect(el.value).to.equal("");
353
+ expect(secondItem.selected).to.be.false;
354
+ el.addEventListener("change", (event) => {
355
+ event.preventDefault();
356
+ preventChangeSpy();
357
+ });
358
+ const closed = oneEvent(el, "sp-closed");
359
+ opened = oneEvent(el, "sp-opened");
360
+ secondItem.click();
361
+ await closed;
362
+ await opened;
363
+ await elementUpdated(el);
364
+ expect(preventChangeSpy.calledOnce).to.be.true;
365
+ expect(secondItem.selected, "selection prevented").to.be.false;
366
+ });
367
+ it("can throw focus after `change`", async () => {
368
+ var _a;
369
+ const input = document.createElement("input");
370
+ document.body.append(input);
371
+ await elementUpdated(el);
372
+ const secondItem = el.querySelector("sp-menu-item:nth-of-type(2)");
373
+ const button = el.button;
374
+ const opened = oneEvent(el, "sp-opened");
375
+ button.click();
376
+ await opened;
377
+ await elementUpdated(el);
378
+ expect(el.open).to.be.true;
379
+ expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
380
+ expect(el.value).to.equal("");
381
+ expect(secondItem.selected).to.be.false;
382
+ el.addEventListener("change", () => {
383
+ input.focus();
384
+ });
385
+ const closed = oneEvent(el, "sp-closed");
386
+ secondItem.click();
387
+ await closed;
388
+ await elementUpdated(el);
389
+ expect(el.open).to.be.false;
390
+ expect(el.value, "value changed").to.equal("option-2");
391
+ expect(secondItem.selected, "selected changed").to.be.true;
392
+ await waitUntil(() => document.activeElement === input, "focus throw");
393
+ input.remove();
394
+ });
395
+ it("opens on ArrowUp", async () => {
396
+ const button = el.button;
397
+ el.focus();
398
+ await elementUpdated(el);
399
+ expect(el.open, "inially closed").to.be.false;
400
+ button.dispatchEvent(tEvent());
401
+ await elementUpdated(el);
402
+ expect(el.open, "still closed").to.be.false;
403
+ button.dispatchEvent(arrowUpEvent());
404
+ await elementUpdated(el);
405
+ expect(el.open, "open by ArrowUp").to.be.true;
406
+ await waitUntil(() => document.querySelector("active-overlay") !== null, "an active-overlay has been inserted on the page");
407
+ button.dispatchEvent(new KeyboardEvent("keyup", {
408
+ bubbles: true,
409
+ composed: true,
410
+ cancelable: true,
411
+ key: "Escape",
412
+ code: "Escape"
413
+ }));
414
+ await elementUpdated(el);
415
+ await waitUntil(() => el.open === false, "closed by Escape");
416
+ await waitUntil(() => document.querySelector("active-overlay") === null, "an active-overlay has been inserted on the page");
417
+ });
418
+ it("opens on ArrowDown", async () => {
419
+ var _a, _b;
420
+ const firstItem = el.querySelector("sp-menu-item:nth-of-type(1)");
421
+ const button = el.button;
422
+ el.focus();
423
+ await elementUpdated(el);
424
+ expect(el.open, "inially closed").to.be.false;
425
+ const opened = oneEvent(el, "sp-opened");
426
+ button.dispatchEvent(arrowDownEvent());
427
+ await opened;
428
+ await elementUpdated(el);
429
+ expect(el.open, "open by ArrowDown").to.be.true;
430
+ expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
431
+ expect(el.value).to.equal("");
432
+ const closed = oneEvent(el, "sp-closed");
433
+ firstItem.click();
434
+ await closed;
435
+ await elementUpdated(el);
436
+ expect(el.open).to.be.false;
437
+ expect((_b = el.selectedItem) == null ? void 0 : _b.itemText).to.equal("Deselect");
438
+ expect(el.value).to.equal("Deselect");
439
+ });
440
+ it("quick selects on ArrowLeft/Right", async () => {
441
+ const selectionSpy = spy();
442
+ el.addEventListener("change", (event) => {
443
+ const { value } = event.target;
444
+ selectionSpy(value);
445
+ });
446
+ const button = el.button;
447
+ el.focus();
448
+ button.dispatchEvent(arrowLeftEvent());
449
+ await elementUpdated(el);
450
+ expect(selectionSpy.callCount).to.equal(1);
451
+ expect(selectionSpy.calledWith("Deselected"));
452
+ button.dispatchEvent(arrowLeftEvent());
453
+ await elementUpdated(el);
454
+ expect(selectionSpy.callCount).to.equal(1);
455
+ button.dispatchEvent(arrowRightEvent());
456
+ await elementUpdated(el);
457
+ expect(selectionSpy.calledWith("option-2"));
458
+ button.dispatchEvent(arrowRightEvent());
459
+ button.dispatchEvent(arrowRightEvent());
460
+ button.dispatchEvent(arrowRightEvent());
461
+ button.dispatchEvent(arrowRightEvent());
462
+ await elementUpdated(el);
463
+ expect(selectionSpy.callCount).to.equal(5);
464
+ expect(selectionSpy.calledWith("Save Selection"));
465
+ expect(selectionSpy.calledWith("Make Work Path")).to.be.false;
466
+ });
467
+ it("quick selects first item on ArrowRight when no value", async () => {
468
+ const selectionSpy = spy();
469
+ el.addEventListener("change", (event) => {
470
+ const { value } = event.target;
471
+ selectionSpy(value);
472
+ });
473
+ const button = el.button;
474
+ el.focus();
475
+ button.dispatchEvent(arrowRightEvent());
476
+ await elementUpdated(el);
477
+ expect(selectionSpy.callCount).to.equal(1);
478
+ expect(selectionSpy.calledWith("Deselected"));
479
+ });
480
+ it("loads", async () => {
481
+ expect(el).to.not.be.undefined;
482
+ });
483
+ it("refocuses on list when open", async () => {
484
+ const firstItem = el.querySelector("sp-menu-item");
485
+ const input = document.createElement("input");
486
+ el.insertAdjacentElement("afterend", input);
487
+ el.focus();
488
+ await sendKeys({ press: "Tab" });
489
+ expect(document.activeElement === input).to.be.true;
490
+ await sendKeys({ press: "Shift+Tab" });
491
+ expect(document.activeElement === el).to.be.true;
492
+ await sendKeys({ press: "Enter" });
493
+ const opened = oneEvent(el, "sp-opened");
494
+ el.open = true;
495
+ await opened;
496
+ await elementUpdated(el);
497
+ await waitUntil(() => firstItem.focused, "The first items should have become focused visually.");
498
+ el.blur();
499
+ await elementUpdated(el);
500
+ expect(el.open).to.be.true;
501
+ el.focus();
502
+ await elementUpdated(el);
503
+ await waitUntil(() => isMenuActiveElement(), "first item refocused");
504
+ expect(el.open).to.be.true;
505
+ expect(isMenuActiveElement()).to.be.true;
506
+ await sendKeys({ press: "ArrowDown" });
507
+ await sendKeys({ press: "ArrowUp" });
508
+ expect(firstItem.focused).to.be.true;
509
+ });
510
+ it("does not allow tabing to close", async () => {
511
+ el.open = true;
512
+ await elementUpdated(el);
513
+ expect(el.open).to.be.true;
514
+ el.focus();
515
+ await elementUpdated(el);
516
+ await waitUntil(() => isMenuActiveElement(), "first item refocused");
517
+ expect(el.open).to.be.true;
518
+ expect(isMenuActiveElement()).to.be.true;
519
+ await sendKeys({ press: "Tab" });
520
+ expect(el.open, "stays open").to.be.true;
521
+ });
522
+ describe("tab order", () => {
523
+ let input1;
524
+ let input2;
525
+ beforeEach(() => {
526
+ const surroundingInput = () => {
527
+ const input = document.createElement("input");
528
+ input.type = "text";
529
+ input.tabIndex = 0;
530
+ return input;
531
+ };
532
+ input1 = surroundingInput();
533
+ input2 = surroundingInput();
534
+ el.insertAdjacentElement("beforebegin", input1);
535
+ el.insertAdjacentElement("afterend", input2);
536
+ });
537
+ afterEach(() => {
538
+ input1.remove();
539
+ input2.remove();
540
+ });
541
+ it("tabs forward through the element", async () => {
542
+ input1.focus();
543
+ await nextFrame();
544
+ expect(document.activeElement === input1, "focuses input 1").to.true;
545
+ let focused = oneEvent(el, "focus");
546
+ await sendKeys({ press: "Tab" });
547
+ await focused;
548
+ expect(el.focused, "focused").to.be.true;
549
+ expect(el.open, "closed").to.be.false;
550
+ expect(document.activeElement === el, "focuses el").to.be.true;
551
+ focused = oneEvent(input2, "focus");
552
+ await sendKeys({ press: "Tab" });
553
+ await focused;
554
+ expect(document.activeElement === input2, "focuses input 2").to.true;
555
+ });
556
+ it("shift+tabs backwards through the element", async () => {
557
+ input2.focus();
558
+ await nextFrame();
559
+ expect(document.activeElement, "focuses input 2").to.equal(input2);
560
+ let focused = oneEvent(el, "focus");
561
+ await sendKeys({ press: "Shift+Tab" });
562
+ await focused;
563
+ expect(el.focused, "focused").to.be.true;
564
+ expect(el.open, "closed").to.be.false;
565
+ expect(document.activeElement, "focuses el").to.equal(el);
566
+ focused = oneEvent(input1, "focus");
567
+ await sendKeys({ press: "Shift+Tab" });
568
+ await focused;
569
+ expect(document.activeElement, "focuses input 1").to.equal(input1);
570
+ });
571
+ it('traps tab in the menu as a `type="modal"` overlay forward', async () => {
572
+ el.focus();
573
+ await nextFrame();
574
+ expect(document.activeElement, "focuses el").to.equal(el);
575
+ const opened = oneEvent(el, "sp-opened");
576
+ await sendKeys({ press: "ArrowDown" });
577
+ await opened;
578
+ expect(el.open, "opened").to.be.true;
579
+ await waitUntil(() => isMenuActiveElement(), "first item focused");
580
+ const activeElement = document.activeElement;
581
+ const blured = oneEvent(activeElement, "blur");
582
+ await sendKeys({ press: "Tab" });
583
+ await blured;
584
+ expect(el.open).to.be.true;
585
+ expect(document.activeElement === input1).to.be.false;
586
+ expect(document.activeElement === input2).to.be.false;
587
+ });
588
+ it('traps tab in the menu as a `type="modal"` overlay backwards', async () => {
589
+ el.focus();
590
+ await nextFrame();
591
+ expect(document.activeElement, "focuses el").to.equal(el);
592
+ const opened = oneEvent(el, "sp-opened");
593
+ await sendKeys({ press: "ArrowDown" });
594
+ await opened;
595
+ expect(el.open, "opened").to.be.true;
596
+ await waitUntil(() => isMenuActiveElement(), "first item focused");
597
+ const activeElement = document.activeElement;
598
+ const blured = oneEvent(activeElement, "blur");
599
+ await sendKeys({ press: "Shift+Tab" });
600
+ await blured;
601
+ expect(el.open).to.be.true;
602
+ expect(document.activeElement === input1).to.be.false;
603
+ expect(document.activeElement === input2).to.be.false;
604
+ });
605
+ it("can close and immediate tab to the next tab stop", async () => {
606
+ el.focus();
607
+ await nextFrame();
608
+ expect(document.activeElement, "focuses el").to.equal(el);
609
+ const opened = oneEvent(el, "sp-opened");
610
+ await sendKeys({ press: "ArrowUp" });
611
+ await opened;
612
+ expect(el.open, "opened").to.be.true;
613
+ await waitUntil(() => isMenuActiveElement(), "first item focused");
614
+ const closed = oneEvent(el, "sp-closed");
615
+ el.open = false;
616
+ await closed;
617
+ expect(el.open).to.be.false;
618
+ expect(document.activeElement === el).to.be.true;
619
+ const focused = oneEvent(input2, "focus");
620
+ await sendKeys({ press: "Tab" });
621
+ await focused;
622
+ expect(el.open).to.be.false;
623
+ expect(document.activeElement === input2).to.be.true;
624
+ });
625
+ it("can close and immediate shift+tab to the previous tab stop", async () => {
626
+ el.focus();
627
+ await nextFrame();
628
+ expect(document.activeElement, "focuses el").to.equal(el);
629
+ const opened = oneEvent(el, "sp-opened");
630
+ await sendKeys({ press: "ArrowUp" });
631
+ await opened;
632
+ expect(el.open, "opened").to.be.true;
633
+ await waitUntil(() => isMenuActiveElement(), "first item focused");
634
+ const closed = oneEvent(el, "sp-closed");
635
+ el.open = false;
636
+ await closed;
637
+ expect(el.open).to.be.false;
638
+ expect(document.activeElement === el).to.be.true;
639
+ const focused = oneEvent(input1, "focus");
640
+ await sendKeys({ press: "Shift+Tab" });
641
+ await focused;
642
+ expect(el.open).to.be.false;
643
+ expect(document.activeElement === input1).to.be.true;
644
+ });
645
+ });
646
+ it("does not open when [readonly]", async () => {
647
+ el.readonly = true;
648
+ await elementUpdated(el);
649
+ const button = el.button;
650
+ button.click();
651
+ await elementUpdated(el);
652
+ expect(el.open).to.be.false;
653
+ });
654
+ it("scrolls selected into view on open", async () => {
655
+ await el.generatePopover();
656
+ el.popover.style.height = "40px";
657
+ const firstItem = el.querySelector("sp-menu-item:first-child");
658
+ const lastItem = el.querySelector("sp-menu-item:last-child");
659
+ lastItem.disabled = false;
660
+ el.value = lastItem.value;
661
+ await elementUpdated(el);
662
+ el.open = true;
663
+ await elementUpdated(el);
664
+ await waitUntil(() => isMenuActiveElement(), "first item focused");
665
+ const getParentOffset = (el2) => {
666
+ const parentScroll = el2.parentElement.scrollTop;
667
+ const parentOffset = el2.offsetTop - parentScroll;
668
+ return parentOffset;
669
+ };
670
+ expect(getParentOffset(lastItem)).to.be.lessThan(40);
671
+ expect(getParentOffset(firstItem)).to.be.lessThan(-1);
672
+ lastItem.dispatchEvent(new FocusEvent("focusin", { bubbles: true }));
673
+ lastItem.dispatchEvent(arrowDownEvent());
674
+ await elementUpdated(el);
675
+ await nextFrame();
676
+ expect(getParentOffset(lastItem)).to.be.greaterThan(40);
677
+ expect(getParentOffset(firstItem)).to.be.greaterThan(-1);
678
+ });
679
+ });
680
+ describe("slotted label", () => {
681
+ const pickerFixture2 = async () => {
682
+ const test = await fixture(html`
698
683
  <div>
699
684
  <sp-field-label for="picker-slotted">
700
685
  Where do you live?
@@ -716,26 +701,26 @@ export function runPickerTests() {
716
701
  </sp-picker>
717
702
  </div>
718
703
  `);
719
- return test.querySelector('sp-picker');
720
- };
721
- beforeEach(async () => {
722
- el = await pickerFixture();
723
- await elementUpdated(el);
724
- });
725
- afterEach(async () => {
726
- if (el.open) {
727
- const closed = oneEvent(el, 'sp-closed');
728
- el.open = false;
729
- await closed;
730
- }
731
- });
732
- it('loads accessibly w/ slotted label', async () => {
733
- await expect(el).to.be.accessible();
734
- });
735
- });
736
- describe('deprecated', () => {
737
- const pickerFixture = async () => {
738
- const test = await fixture(html `
704
+ return test.querySelector("sp-picker");
705
+ };
706
+ beforeEach(async () => {
707
+ el = await pickerFixture2();
708
+ await elementUpdated(el);
709
+ });
710
+ afterEach(async () => {
711
+ if (el.open) {
712
+ const closed = oneEvent(el, "sp-closed");
713
+ el.open = false;
714
+ await closed;
715
+ }
716
+ });
717
+ it("loads accessibly w/ slotted label", async () => {
718
+ await expect(el).to.be.accessible();
719
+ });
720
+ });
721
+ describe("deprecated", () => {
722
+ const pickerFixture2 = async () => {
723
+ const test = await fixture(html`
739
724
  <div>
740
725
  <sp-field-label for="picker-deprecated">
741
726
  Where do you live?
@@ -760,85 +745,85 @@ export function runPickerTests() {
760
745
  </sp-picker>
761
746
  </div>
762
747
  `);
763
- return test.querySelector('sp-picker');
764
- };
765
- beforeEach(async () => {
766
- el = await pickerFixture();
767
- await elementUpdated(el);
768
- });
769
- afterEach(async () => {
770
- if (el.open) {
771
- const closed = oneEvent(el, 'sp-closed');
772
- el.open = false;
773
- await closed;
774
- }
775
- });
776
- it('selects with deprecated syntax', async () => {
777
- var _a, _b;
778
- const secondItem = el.querySelector('sp-menu-item:nth-of-type(2)');
779
- const opened = oneEvent(el, 'sp-opened');
780
- el.button.click();
781
- await opened;
782
- await elementUpdated(el);
783
- expect(el.open).to.be.true;
784
- expect((_a = el.selectedItem) === null || _a === void 0 ? void 0 : _a.itemText).to.be.undefined;
785
- expect(el.value).to.equal('');
786
- const closed = oneEvent(el, 'sp-closed');
787
- secondItem.click();
788
- await closed;
789
- expect(el.open).to.be.false;
790
- expect((_b = el.selectedItem) === null || _b === void 0 ? void 0 : _b.itemText).to.equal('Select Inverse');
791
- expect(el.value).to.equal('option-2');
792
- });
793
- });
794
- it('manages its "name" value in the accessibility tree when [icons-only]', async () => {
795
- const test = await fixture(html `
748
+ return test.querySelector("sp-picker");
749
+ };
750
+ beforeEach(async () => {
751
+ el = await pickerFixture2();
752
+ await elementUpdated(el);
753
+ });
754
+ afterEach(async () => {
755
+ if (el.open) {
756
+ const closed = oneEvent(el, "sp-closed");
757
+ el.open = false;
758
+ await closed;
759
+ }
760
+ });
761
+ it("selects with deprecated syntax", async () => {
762
+ var _a, _b;
763
+ const secondItem = el.querySelector("sp-menu-item:nth-of-type(2)");
764
+ const opened = oneEvent(el, "sp-opened");
765
+ el.button.click();
766
+ await opened;
767
+ await elementUpdated(el);
768
+ expect(el.open).to.be.true;
769
+ expect((_a = el.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
770
+ expect(el.value).to.equal("");
771
+ const closed = oneEvent(el, "sp-closed");
772
+ secondItem.click();
773
+ await closed;
774
+ expect(el.open).to.be.false;
775
+ expect((_b = el.selectedItem) == null ? void 0 : _b.itemText).to.equal("Select Inverse");
776
+ expect(el.value).to.equal("option-2");
777
+ });
778
+ });
779
+ it('manages its "name" value in the accessibility tree when [icons-only]', async () => {
780
+ const test = await fixture(html`
796
781
  <div>${iconsOnly({})}</div>
797
782
  `);
798
- const el = test.querySelector('sp-picker');
799
- await elementUpdated(el);
800
- let snapshot = (await a11ySnapshot({}));
801
- expect(findAccessibilityNode(snapshot, (node) => node.name === 'Choose an action type... Delete'), '`name` is the label text').to.not.be.null;
802
- el.value = '2';
803
- await elementUpdated(el);
804
- snapshot = (await a11ySnapshot({}));
805
- expect(findAccessibilityNode(snapshot, (node) => node.name === 'Choose an action type... Copy'), '`name` is the label text plus the selected item text').to.not.be.null;
806
- });
807
- it('toggles between pickers', async () => {
808
- const el2 = await pickerFixture();
809
- const el1 = await pickerFixture();
810
- el1.id = 'away';
811
- el2.id = 'other';
812
- await Promise.all([elementUpdated(el1), elementUpdated(el2)]);
813
- expect(el1.open, 'closed 1').to.be.false;
814
- expect(el2.open, 'closed 1').to.be.false;
815
- let open = oneEvent(el1, 'sp-opened');
816
- el1.click();
817
- await open;
818
- expect(el1.open).to.be.true;
819
- expect(el2.open).to.be.false;
820
- open = oneEvent(el2, 'sp-opened');
821
- let closed = oneEvent(el1, 'sp-closed');
822
- el2.click();
823
- await Promise.all([open, closed]);
824
- expect(el1.open).to.be.false;
825
- expect(el2.open).to.be.true;
826
- open = oneEvent(el1, 'sp-opened');
827
- closed = oneEvent(el2, 'sp-closed');
828
- el1.click();
829
- await Promise.all([open, closed]);
830
- expect(el1.open).to.be.true;
831
- expect(el2.open).to.be.false;
832
- closed = oneEvent(el1, 'sp-closed');
833
- sendKeys({
834
- press: 'Escape',
835
- });
836
- await closed;
837
- expect(el1.open).to.be.false;
783
+ const el2 = test.querySelector("sp-picker");
784
+ await elementUpdated(el2);
785
+ let snapshot = await a11ySnapshot({});
786
+ expect(findAccessibilityNode(snapshot, (node) => node.name === "Choose an action type... Delete"), "`name` is the label text").to.not.be.null;
787
+ el2.value = "2";
788
+ await elementUpdated(el2);
789
+ snapshot = await a11ySnapshot({});
790
+ expect(findAccessibilityNode(snapshot, (node) => node.name === "Choose an action type... Copy"), "`name` is the label text plus the selected item text").to.not.be.null;
791
+ });
792
+ it("toggles between pickers", async () => {
793
+ const el2 = await pickerFixture();
794
+ const el1 = await pickerFixture();
795
+ el1.id = "away";
796
+ el2.id = "other";
797
+ await Promise.all([elementUpdated(el1), elementUpdated(el2)]);
798
+ expect(el1.open, "closed 1").to.be.false;
799
+ expect(el2.open, "closed 1").to.be.false;
800
+ let open = oneEvent(el1, "sp-opened");
801
+ el1.click();
802
+ await open;
803
+ expect(el1.open).to.be.true;
804
+ expect(el2.open).to.be.false;
805
+ open = oneEvent(el2, "sp-opened");
806
+ let closed = oneEvent(el1, "sp-closed");
807
+ el2.click();
808
+ await Promise.all([open, closed]);
809
+ expect(el1.open).to.be.false;
810
+ expect(el2.open).to.be.true;
811
+ open = oneEvent(el1, "sp-opened");
812
+ closed = oneEvent(el2, "sp-closed");
813
+ el1.click();
814
+ await Promise.all([open, closed]);
815
+ expect(el1.open).to.be.true;
816
+ expect(el2.open).to.be.false;
817
+ closed = oneEvent(el1, "sp-closed");
818
+ sendKeys({
819
+ press: "Escape"
838
820
  });
839
- it('displays selected item text by default', async () => {
840
- var _a, _b, _c, _d;
841
- const el = await fixture(html `
821
+ await closed;
822
+ expect(el1.open).to.be.false;
823
+ });
824
+ it("displays selected item text by default", async () => {
825
+ var _a, _b, _c, _d;
826
+ const el2 = await fixture(html`
842
827
  <sp-picker
843
828
  value="inverse"
844
829
  label="Select a Country with a very long label, too long in fact"
@@ -852,27 +837,30 @@ export function runPickerTests() {
852
837
  <sp-menu-item disabled>Make Work Path</sp-menu-item>
853
838
  </sp-picker>
854
839
  `);
855
- await elementUpdated(el);
856
- await waitUntil(() => { var _a; return ((_a = el.selectedItem) === null || _a === void 0 ? void 0 : _a.itemText) === 'Select Inverse'; }, `Selected Item Text: ${(_a = el.selectedItem) === null || _a === void 0 ? void 0 : _a.itemText}`);
857
- const firstItem = el.querySelector('sp-menu-item:nth-of-type(1)');
858
- const secondItem = el.querySelector('sp-menu-item:nth-of-type(2)');
859
- expect(el.value).to.equal('inverse');
860
- expect((_b = el.selectedItem) === null || _b === void 0 ? void 0 : _b.itemText).to.equal('Select Inverse');
861
- el.focus();
862
- await elementUpdated(el);
863
- expect(el === document.activeElement, `activeElement is ${(_c = document.activeElement) === null || _c === void 0 ? void 0 : _c.localName}`).to.be.true;
864
- const opened = oneEvent(el, 'sp-opened');
865
- sendKeys({ press: 'Enter' });
866
- await opened;
867
- await elementUpdated(el.optionsMenu);
868
- expect(el.optionsMenu === document.activeElement, `activeElement is ${(_d = document.activeElement) === null || _d === void 0 ? void 0 : _d.localName}`).to.be.true;
869
- expect(firstItem.focused, 'firstItem NOT "focused"').to.be.false;
870
- expect(secondItem.focused, 'secondItem "focused"').to.be.true;
871
- expect(el.optionsMenu.getAttribute('aria-activedescendant')).to.equal(secondItem.id);
872
- });
873
- it('resets value when item not available', async () => {
874
- var _a;
875
- const el = await fixture(html `
840
+ await elementUpdated(el2);
841
+ await waitUntil(() => {
842
+ var _a2;
843
+ return ((_a2 = el2.selectedItem) == null ? void 0 : _a2.itemText) === "Select Inverse";
844
+ }, `Selected Item Text: ${(_a = el2.selectedItem) == null ? void 0 : _a.itemText}`);
845
+ const firstItem = el2.querySelector("sp-menu-item:nth-of-type(1)");
846
+ const secondItem = el2.querySelector("sp-menu-item:nth-of-type(2)");
847
+ expect(el2.value).to.equal("inverse");
848
+ expect((_b = el2.selectedItem) == null ? void 0 : _b.itemText).to.equal("Select Inverse");
849
+ el2.focus();
850
+ await elementUpdated(el2);
851
+ expect(el2 === document.activeElement, `activeElement is ${(_c = document.activeElement) == null ? void 0 : _c.localName}`).to.be.true;
852
+ const opened = oneEvent(el2, "sp-opened");
853
+ sendKeys({ press: "Enter" });
854
+ await opened;
855
+ await elementUpdated(el2.optionsMenu);
856
+ expect(el2.optionsMenu === document.activeElement, `activeElement is ${(_d = document.activeElement) == null ? void 0 : _d.localName}`).to.be.true;
857
+ expect(firstItem.focused, 'firstItem NOT "focused"').to.be.false;
858
+ expect(secondItem.focused, 'secondItem "focused"').to.be.true;
859
+ expect(el2.optionsMenu.getAttribute("aria-activedescendant")).to.equal(secondItem.id);
860
+ });
861
+ it("resets value when item not available", async () => {
862
+ var _a;
863
+ const el2 = await fixture(html`
876
864
  <sp-picker
877
865
  value="missing"
878
866
  label="Select a Country with a very long label, too long in fact"
@@ -886,15 +874,15 @@ export function runPickerTests() {
886
874
  <sp-menu-item disabled>Make Work Path</sp-menu-item>
887
875
  </sp-picker>
888
876
  `);
889
- await elementUpdated(el);
890
- await waitUntil(() => el.value === '');
891
- expect(el.value).to.equal('');
892
- expect((_a = el.selectedItem) === null || _a === void 0 ? void 0 : _a.itemText).to.be.undefined;
893
- });
894
- it('allows event listeners on child items', async () => {
895
- const mouseenterSpy = spy();
896
- const handleMouseenter = () => mouseenterSpy();
897
- const el = await fixture(html `
877
+ await elementUpdated(el2);
878
+ await waitUntil(() => el2.value === "");
879
+ expect(el2.value).to.equal("");
880
+ expect((_a = el2.selectedItem) == null ? void 0 : _a.itemText).to.be.undefined;
881
+ });
882
+ it("allows event listeners on child items", async () => {
883
+ const mouseenterSpy = spy();
884
+ const handleMouseenter = () => mouseenterSpy();
885
+ const el2 = await fixture(html`
898
886
  <sp-picker
899
887
  label="Select a Country with a very long label, too long in fact"
900
888
  >
@@ -906,29 +894,29 @@ export function runPickerTests() {
906
894
  </sp-menu-item>
907
895
  </sp-picker>
908
896
  `);
909
- await elementUpdated(el);
910
- const hoverEl = el.querySelector('sp-menu-item');
911
- const opened = oneEvent(el, 'sp-opened');
912
- el.open = true;
913
- await opened;
914
- await elementUpdated(el);
915
- expect(el.open).to.be.true;
916
- hoverEl.dispatchEvent(new MouseEvent('mouseenter'));
917
- await elementUpdated(el);
918
- expect(el.open).to.be.true;
919
- const closed = oneEvent(el, 'sp-closed');
920
- el.open = false;
921
- await closed;
922
- await elementUpdated(el);
923
- expect(el.open).to.be.false;
924
- expect(mouseenterSpy.calledOnce).to.be.true;
925
- });
926
- it('dispatches events on open/close', async () => {
927
- const openedSpy = spy();
928
- const closedSpy = spy();
929
- const handleOpenedSpy = (event) => openedSpy(event);
930
- const handleClosedSpy = (event) => closedSpy(event);
931
- const el = await fixture(html `
897
+ await elementUpdated(el2);
898
+ const hoverEl = el2.querySelector("sp-menu-item");
899
+ const opened = oneEvent(el2, "sp-opened");
900
+ el2.open = true;
901
+ await opened;
902
+ await elementUpdated(el2);
903
+ expect(el2.open).to.be.true;
904
+ hoverEl.dispatchEvent(new MouseEvent("mouseenter"));
905
+ await elementUpdated(el2);
906
+ expect(el2.open).to.be.true;
907
+ const closed = oneEvent(el2, "sp-closed");
908
+ el2.open = false;
909
+ await closed;
910
+ await elementUpdated(el2);
911
+ expect(el2.open).to.be.false;
912
+ expect(mouseenterSpy.calledOnce).to.be.true;
913
+ });
914
+ it("dispatches events on open/close", async () => {
915
+ const openedSpy = spy();
916
+ const closedSpy = spy();
917
+ const handleOpenedSpy = (event) => openedSpy(event);
918
+ const handleClosedSpy = (event) => closedSpy(event);
919
+ const el2 = await fixture(html`
932
920
  <sp-picker
933
921
  label="Select a Country with a very long label, too long in fact"
934
922
  @sp-opened=${handleOpenedSpy}
@@ -937,24 +925,22 @@ export function runPickerTests() {
937
925
  <sp-menu-item value="deselect">Deselect Text</sp-menu-item>
938
926
  </sp-picker>
939
927
  `);
940
- await elementUpdated(el);
941
- const opened = oneEvent(el, 'sp-opened');
942
- el.open = true;
943
- await opened;
944
- await elementUpdated(el);
945
- expect(openedSpy.calledOnce).to.be.true;
946
- expect(closedSpy.calledOnce).to.be.false;
947
- const openedEvent = openedSpy
948
- .args[0][0];
949
- expect(openedEvent.detail.interaction).to.equal('modal');
950
- const closed = oneEvent(el, 'sp-closed');
951
- el.open = false;
952
- await closed;
953
- await elementUpdated(el);
954
- expect(closedSpy.calledOnce).to.be.true;
955
- const closedEvent = closedSpy
956
- .args[0][0];
957
- expect(closedEvent.detail.interaction).to.equal('modal');
958
- });
928
+ await elementUpdated(el2);
929
+ const opened = oneEvent(el2, "sp-opened");
930
+ el2.open = true;
931
+ await opened;
932
+ await elementUpdated(el2);
933
+ expect(openedSpy.calledOnce).to.be.true;
934
+ expect(closedSpy.calledOnce).to.be.false;
935
+ const openedEvent = openedSpy.args[0][0];
936
+ expect(openedEvent.detail.interaction).to.equal("modal");
937
+ const closed = oneEvent(el2, "sp-closed");
938
+ el2.open = false;
939
+ await closed;
940
+ await elementUpdated(el2);
941
+ expect(closedSpy.calledOnce).to.be.true;
942
+ const closedEvent = closedSpy.args[0][0];
943
+ expect(closedEvent.detail.interaction).to.equal("modal");
944
+ });
959
945
  }
960
- //# sourceMappingURL=index.js.map
946
+ //# sourceMappingURL=index.js.map