@spectrum-web-components/picker 0.11.3 → 0.11.6-devmode.0

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