@spectrum-web-components/picker 1.1.0-beta.8 → 1.1.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 (94) hide show
  1. package/README.md +33 -4
  2. package/package.json +17 -17
  3. package/sp-picker.d.ts +0 -6
  4. package/sp-picker.dev.js +0 -5
  5. package/sp-picker.dev.js.map +0 -7
  6. package/sp-picker.js +0 -2
  7. package/sp-picker.js.map +0 -7
  8. package/src/DesktopController.d.ts +0 -7
  9. package/src/DesktopController.dev.js +0 -72
  10. package/src/DesktopController.dev.js.map +0 -7
  11. package/src/DesktopController.js +0 -2
  12. package/src/DesktopController.js.map +0 -7
  13. package/src/InteractionController.d.ts +0 -43
  14. package/src/InteractionController.dev.js +0 -121
  15. package/src/InteractionController.dev.js.map +0 -7
  16. package/src/InteractionController.js +0 -2
  17. package/src/InteractionController.js.map +0 -7
  18. package/src/MobileController.d.ts +0 -9
  19. package/src/MobileController.dev.js +0 -51
  20. package/src/MobileController.dev.js.map +0 -7
  21. package/src/MobileController.js +0 -2
  22. package/src/MobileController.js.map +0 -7
  23. package/src/Picker.d.ts +0 -133
  24. package/src/Picker.dev.js +0 -713
  25. package/src/Picker.dev.js.map +0 -7
  26. package/src/Picker.js +0 -116
  27. package/src/Picker.js.map +0 -7
  28. package/src/index.d.ts +0 -1
  29. package/src/index.dev.js +0 -3
  30. package/src/index.dev.js.map +0 -7
  31. package/src/index.js +0 -2
  32. package/src/index.js.map +0 -7
  33. package/src/picker-overrides.css.d.ts +0 -2
  34. package/src/picker-overrides.css.dev.js +0 -7
  35. package/src/picker-overrides.css.dev.js.map +0 -7
  36. package/src/picker-overrides.css.js +0 -4
  37. package/src/picker-overrides.css.js.map +0 -7
  38. package/src/picker.css.d.ts +0 -2
  39. package/src/picker.css.dev.js +0 -7
  40. package/src/picker.css.dev.js.map +0 -7
  41. package/src/picker.css.js +0 -4
  42. package/src/picker.css.js.map +0 -7
  43. package/src/spectrum-picker.css.d.ts +0 -2
  44. package/src/spectrum-picker.css.dev.js +0 -7
  45. package/src/spectrum-picker.css.dev.js.map +0 -7
  46. package/src/spectrum-picker.css.js +0 -4
  47. package/src/spectrum-picker.css.js.map +0 -7
  48. package/src/strategies.d.ts +0 -6
  49. package/src/strategies.dev.js +0 -8
  50. package/src/strategies.dev.js.map +0 -7
  51. package/src/strategies.js +0 -2
  52. package/src/strategies.js.map +0 -7
  53. package/stories/args.js +0 -56
  54. package/stories/args.js.map +0 -7
  55. package/stories/picker-pending.stories.js +0 -16
  56. package/stories/picker-pending.stories.js.map +0 -7
  57. package/stories/picker-sizes.stories.js +0 -75
  58. package/stories/picker-sizes.stories.js.map +0 -7
  59. package/stories/picker.stories.js +0 -606
  60. package/stories/picker.stories.js.map +0 -7
  61. package/stories/states.js +0 -228
  62. package/stories/states.js.map +0 -7
  63. package/stories/template.js +0 -32
  64. package/stories/template.js.map +0 -7
  65. package/sync/index.d.ts +0 -3
  66. package/sync/index.dev.js +0 -5
  67. package/sync/index.dev.js.map +0 -7
  68. package/sync/index.js +0 -2
  69. package/sync/index.js.map +0 -7
  70. package/sync/sp-picker.d.ts +0 -2
  71. package/sync/sp-picker.dev.js +0 -4
  72. package/sync/sp-picker.dev.js.map +0 -7
  73. package/sync/sp-picker.js +0 -2
  74. package/sync/sp-picker.js.map +0 -7
  75. package/test/benchmark/basic-test.js +0 -269
  76. package/test/benchmark/basic-test.js.map +0 -7
  77. package/test/index.js +0 -1680
  78. package/test/index.js.map +0 -7
  79. package/test/picker-memory.test.js +0 -5
  80. package/test/picker-memory.test.js.map +0 -7
  81. package/test/picker-pending.test-vrt.js +0 -5
  82. package/test/picker-pending.test-vrt.js.map +0 -7
  83. package/test/picker-reparenting.test.js +0 -92
  84. package/test/picker-reparenting.test.js.map +0 -7
  85. package/test/picker-responsive.test.js +0 -75
  86. package/test/picker-responsive.test.js.map +0 -7
  87. package/test/picker-sizes.test-vrt.js +0 -5
  88. package/test/picker-sizes.test-vrt.js.map +0 -7
  89. package/test/picker-sync.test.js +0 -7
  90. package/test/picker-sync.test.js.map +0 -7
  91. package/test/picker.test-vrt.js +0 -5
  92. package/test/picker.test-vrt.js.map +0 -7
  93. package/test/picker.test.js +0 -7
  94. package/test/picker.test.js.map +0 -7
package/src/Picker.dev.js DELETED
@@ -1,713 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __decorateClass = (decorators, target, key, kind) => {
5
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
6
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
7
- if (decorator = decorators[i])
8
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
9
- if (kind && result) __defProp(target, key, result);
10
- return result;
11
- };
12
- import {
13
- html,
14
- nothing,
15
- render,
16
- SizedMixin
17
- } from "@spectrum-web-components/base";
18
- import {
19
- classMap,
20
- ifDefined,
21
- styleMap
22
- } from "@spectrum-web-components/base/src/directives.js";
23
- import {
24
- property,
25
- query,
26
- state
27
- } from "@spectrum-web-components/base/src/decorators.js";
28
- import pickerStyles from "./picker.css.js";
29
- import chevronStyles from "@spectrum-web-components/icon/src/spectrum-icon-chevron.css.js";
30
- import chevronIconOverrides from "@spectrum-web-components/icon/src/icon-chevron-overrides.css.js";
31
- import { Focusable } from "@spectrum-web-components/shared/src/focusable.js";
32
- import "@spectrum-web-components/icons-ui/icons/sp-icon-chevron100.js";
33
- import "@spectrum-web-components/icons-workflow/icons/sp-icon-alert.js";
34
- import "@spectrum-web-components/menu/sp-menu.js";
35
- import {
36
- IS_MOBILE,
37
- MatchMediaController
38
- } from "@spectrum-web-components/reactive-controllers/src/MatchMedia.js";
39
- import { DependencyManagerController } from "@spectrum-web-components/reactive-controllers/src/DependencyManger.js";
40
- import { PendingStateController } from "@spectrum-web-components/reactive-controllers/src/PendingState.js";
41
- import { strategies } from "./strategies.dev.js";
42
- const chevronClass = {
43
- s: "spectrum-UIIcon-ChevronDown75",
44
- m: "spectrum-UIIcon-ChevronDown100",
45
- l: "spectrum-UIIcon-ChevronDown200",
46
- xl: "spectrum-UIIcon-ChevronDown300"
47
- };
48
- export const DESCRIPTION_ID = "option-picker";
49
- export class PickerBase extends SizedMixin(Focusable, { noDefaultSize: true }) {
50
- /**
51
- * Initializes the `PendingStateController` for the Picker component.
52
- * The `PendingStateController` manages the pending state of the Picker.
53
- */
54
- constructor() {
55
- super();
56
- this.isMobile = new MatchMediaController(this, IS_MOBILE);
57
- this.dependencyManager = new DependencyManagerController(this);
58
- this.deprecatedMenu = null;
59
- this.disabled = false;
60
- this.focused = false;
61
- this.invalid = false;
62
- this.pending = false;
63
- this.pendingLabel = "Pending";
64
- this.open = false;
65
- this.readonly = false;
66
- this.selects = "single";
67
- this._selfManageFocusElement = false;
68
- this.placement = "bottom-start";
69
- this.quiet = false;
70
- this.value = "";
71
- this.listRole = "listbox";
72
- this.itemRole = "option";
73
- this.handleKeydown = (event) => {
74
- this.focused = true;
75
- if (event.code !== "ArrowDown" && event.code !== "ArrowUp") {
76
- return;
77
- }
78
- event.stopPropagation();
79
- event.preventDefault();
80
- this.toggle(true);
81
- };
82
- this.handleSlottableRequest = (_event) => {
83
- };
84
- this.applyFocusElementLabel = (value, labelElement) => {
85
- this.appliedLabel = value;
86
- this.labelAlignment = labelElement.sideAligned ? "inline" : void 0;
87
- };
88
- this.hasRenderedOverlay = false;
89
- this.willManageSelection = false;
90
- this.selectionPromise = Promise.resolve();
91
- this.recentlyConnected = false;
92
- this.enterKeydownOn = null;
93
- this.handleEnterKeydown = (event) => {
94
- if (event.code !== "Enter") {
95
- return;
96
- }
97
- if (this.enterKeydownOn) {
98
- event.preventDefault();
99
- return;
100
- }
101
- this.enterKeydownOn = event.target;
102
- this.addEventListener(
103
- "keyup",
104
- async (keyupEvent) => {
105
- if (keyupEvent.code !== "Enter") {
106
- return;
107
- }
108
- this.enterKeydownOn = null;
109
- },
110
- { once: true }
111
- );
112
- };
113
- this.pendingStateController = new PendingStateController(this);
114
- }
115
- get menuItems() {
116
- return this.optionsMenu.childItems;
117
- }
118
- get selfManageFocusElement() {
119
- return this._selfManageFocusElement;
120
- }
121
- get selectedItem() {
122
- return this._selectedItem;
123
- }
124
- set selectedItem(selectedItem) {
125
- this.selectedItemContent = selectedItem ? selectedItem.itemChildren : void 0;
126
- if (selectedItem === this.selectedItem) return;
127
- const oldSelectedItem = this.selectedItem;
128
- this._selectedItem = selectedItem;
129
- this.requestUpdate("selectedItem", oldSelectedItem);
130
- }
131
- get focusElement() {
132
- if (this.open) {
133
- return this.optionsMenu;
134
- }
135
- return this.button;
136
- }
137
- forceFocusVisible() {
138
- if (this.disabled) {
139
- return;
140
- }
141
- this.focused = true;
142
- }
143
- click() {
144
- if (this.disabled) {
145
- return;
146
- }
147
- this.toggle();
148
- }
149
- handleButtonBlur() {
150
- this.focused = false;
151
- }
152
- focus(options) {
153
- super.focus(options);
154
- if (!this.disabled && this.focusElement) {
155
- this.focused = this.hasVisibleFocusInTree();
156
- }
157
- }
158
- handleHelperFocus() {
159
- this.focused = true;
160
- this.button.focus();
161
- }
162
- handleChange(event) {
163
- if (this.strategy) {
164
- this.strategy.preventNextToggle = "no";
165
- }
166
- const target = event.target;
167
- const [selected] = target.selectedItems;
168
- event.stopPropagation();
169
- if (event.cancelable) {
170
- this.setValueFromItem(selected, event);
171
- } else {
172
- this.open = false;
173
- if (this.strategy) {
174
- this.strategy.open = false;
175
- }
176
- }
177
- }
178
- handleButtonFocus(event) {
179
- var _a;
180
- (_a = this.strategy) == null ? void 0 : _a.handleButtonFocus(event);
181
- }
182
- async setValueFromItem(item, menuChangeEvent) {
183
- var _a;
184
- this.open = false;
185
- if (this.strategy) {
186
- this.strategy.open = false;
187
- }
188
- const oldSelectedItem = this.selectedItem;
189
- const oldValue = this.value;
190
- this.selectedItem = item;
191
- this.value = (_a = item == null ? void 0 : item.value) != null ? _a : "";
192
- await this.updateComplete;
193
- const applyDefault = this.dispatchEvent(
194
- new Event("change", {
195
- bubbles: true,
196
- // Allow it to be prevented.
197
- cancelable: true,
198
- composed: true
199
- })
200
- );
201
- if (!applyDefault && this.selects) {
202
- if (menuChangeEvent) {
203
- menuChangeEvent.preventDefault();
204
- }
205
- this.setMenuItemSelected(this.selectedItem, false);
206
- if (oldSelectedItem) {
207
- this.setMenuItemSelected(oldSelectedItem, true);
208
- }
209
- this.selectedItem = oldSelectedItem;
210
- this.value = oldValue;
211
- this.open = true;
212
- if (this.strategy) {
213
- this.strategy.open = true;
214
- }
215
- return;
216
- } else if (!this.selects) {
217
- this.selectedItem = oldSelectedItem;
218
- this.value = oldValue;
219
- return;
220
- }
221
- if (oldSelectedItem) {
222
- this.setMenuItemSelected(oldSelectedItem, false);
223
- }
224
- this.setMenuItemSelected(item, !!this.selects);
225
- }
226
- setMenuItemSelected(item, value) {
227
- if (this.selects == null) return;
228
- item.selected = value;
229
- }
230
- toggle(target) {
231
- if (this.readonly || this.pending) {
232
- return;
233
- }
234
- this.open = typeof target !== "undefined" ? target : !this.open;
235
- if (this.strategy) {
236
- this.strategy.open = this.open;
237
- }
238
- if (this.open) {
239
- this._selfManageFocusElement = true;
240
- } else {
241
- this._selfManageFocusElement = false;
242
- }
243
- }
244
- close() {
245
- if (this.readonly) {
246
- return;
247
- }
248
- if (this.strategy) {
249
- this.open = false;
250
- this.strategy.open = false;
251
- }
252
- }
253
- get containerStyles() {
254
- if (this.isMobile.matches) {
255
- return {
256
- "--swc-menu-width": "100%"
257
- };
258
- }
259
- return {};
260
- }
261
- get selectedItemContent() {
262
- return this._selectedItemContent || { icon: [], content: [] };
263
- }
264
- set selectedItemContent(selectedItemContent) {
265
- if (selectedItemContent === this.selectedItemContent) return;
266
- const oldContent = this.selectedItemContent;
267
- this._selectedItemContent = selectedItemContent;
268
- this.requestUpdate("selectedItemContent", oldContent);
269
- }
270
- handleTooltipSlotchange(event) {
271
- this.tooltipEl = event.target.assignedElements()[0];
272
- }
273
- renderLabelContent(content) {
274
- if (this.value && this.selectedItem) {
275
- return content;
276
- }
277
- return html`
278
- <slot name="label" id="label">
279
- <span
280
- aria-hidden=${ifDefined(
281
- this.appliedLabel ? void 0 : "true"
282
- )}
283
- >
284
- ${this.label}
285
- </span>
286
- </slot>
287
- `;
288
- }
289
- get buttonContent() {
290
- const labelClasses = {
291
- "visually-hidden": this.icons === "only" && !!this.value,
292
- placeholder: !this.value,
293
- label: true
294
- };
295
- const appliedLabel = this.appliedLabel || this.label;
296
- return [
297
- html`
298
- <span id="icon" ?hidden=${this.icons === "none"}>
299
- ${this.selectedItemContent.icon}
300
- </span>
301
- <span
302
- id=${ifDefined(
303
- this.value && this.selectedItem ? "label" : void 0
304
- )}
305
- class=${classMap(labelClasses)}
306
- >
307
- ${this.renderLabelContent(this.selectedItemContent.content)}
308
- </span>
309
- ${this.value && this.selectedItem ? html`
310
- <span
311
- aria-hidden="true"
312
- class="visually-hidden"
313
- id="applied-label"
314
- >
315
- ${appliedLabel}
316
- <slot name="label"></slot>
317
- </span>
318
- ` : html`
319
- <span hidden id="applied-label">${appliedLabel}</span>
320
- `}
321
- ${this.invalid && !this.pending ? html`
322
- <sp-icon-alert
323
- class="validation-icon"
324
- ></sp-icon-alert>
325
- ` : nothing}
326
- ${this.pendingStateController.renderPendingState()}
327
- <sp-icon-chevron100
328
- class="picker ${chevronClass[this.size]}"
329
- ></sp-icon-chevron100>
330
- <slot
331
- aria-hidden="true"
332
- name="tooltip"
333
- id="tooltip"
334
- @slotchange=${this.handleTooltipSlotchange}
335
- ></slot>
336
- `
337
- ];
338
- }
339
- renderOverlay(menu) {
340
- var _a, _b, _c;
341
- if (((_a = this.strategy) == null ? void 0 : _a.overlay) === void 0) {
342
- return menu;
343
- }
344
- const container = this.renderContainer(menu);
345
- render(container, (_b = this.strategy) == null ? void 0 : _b.overlay, {
346
- host: this
347
- });
348
- return (_c = this.strategy) == null ? void 0 : _c.overlay;
349
- }
350
- get renderDescriptionSlot() {
351
- return html`
352
- <div id=${DESCRIPTION_ID}>
353
- <slot name="description"></slot>
354
- </div>
355
- `;
356
- }
357
- // a helper to throw focus to the button is needed because Safari
358
- // won't include buttons in the tab order even with tabindex="0"
359
- render() {
360
- if (this.tooltipEl) {
361
- this.tooltipEl.disabled = this.open;
362
- }
363
- return html`
364
- <span
365
- id="focus-helper"
366
- tabindex="${this.focused || this.open ? "-1" : "0"}"
367
- @focus=${this.handleHelperFocus}
368
- aria-describedby=${DESCRIPTION_ID}
369
- ></span>
370
- <button
371
- aria-controls=${ifDefined(this.open ? "menu" : void 0)}
372
- aria-describedby="tooltip"
373
- aria-expanded=${this.open ? "true" : "false"}
374
- aria-haspopup="true"
375
- aria-labelledby="loader icon label applied-label"
376
- id="button"
377
- class=${ifDefined(
378
- this.labelAlignment ? `label-${this.labelAlignment}` : void 0
379
- )}
380
- @blur=${this.handleButtonBlur}
381
- @keydown=${{
382
- handleEvent: this.handleEnterKeydown,
383
- capture: true
384
- }}
385
- ?disabled=${this.disabled}
386
- tabindex="-1"
387
- >
388
- ${this.buttonContent}
389
- </button>
390
- ${this.renderMenu} ${this.renderDescriptionSlot}
391
- `;
392
- }
393
- update(changes) {
394
- var _a, _b;
395
- if (this.selects) {
396
- this.selects = "single";
397
- }
398
- if (changes.has("disabled") && this.disabled) {
399
- if (this.strategy) {
400
- this.open = false;
401
- this.strategy.open = false;
402
- }
403
- }
404
- if (changes.has("pending") && this.pending) {
405
- if (this.strategy) {
406
- this.open = false;
407
- this.strategy.open = false;
408
- }
409
- }
410
- if (changes.has("value")) {
411
- this.shouldScheduleManageSelection();
412
- }
413
- if (!this.hasUpdated) {
414
- this.deprecatedMenu = this.querySelector(":scope > sp-menu");
415
- (_a = this.deprecatedMenu) == null ? void 0 : _a.toggleAttribute("ignore", true);
416
- (_b = this.deprecatedMenu) == null ? void 0 : _b.setAttribute("selects", "inherit");
417
- }
418
- if (true) {
419
- if (!this.hasUpdated && this.querySelector(":scope > sp-menu")) {
420
- const { localName } = this;
421
- window.__swc.warn(
422
- this,
423
- `You no longer need to provide an <sp-menu> child to ${localName}. Any styling or attributes on the <sp-menu> will be ignored.`,
424
- "https://opensource.adobe.com/spectrum-web-components/components/picker/#sizes",
425
- { level: "deprecation" }
426
- );
427
- }
428
- this.updateComplete.then(async () => {
429
- await new Promise((res) => requestAnimationFrame(res));
430
- await new Promise((res) => requestAnimationFrame(res));
431
- if (!this.label && !this.getAttribute("aria-label") && !this.getAttribute("aria-labelledby") && !this.appliedLabel) {
432
- window.__swc.warn(
433
- this,
434
- `<${this.localName}> needs one of the following to be accessible:`,
435
- "https://opensource.adobe.com/spectrum-web-components/components/picker/#accessibility",
436
- {
437
- type: "accessibility",
438
- issues: [
439
- `an <sp-field-label> element with a \`for\` attribute referencing the \`id\` of the \`<${this.localName}>\`, or`,
440
- 'value supplied to the "label" attribute, which will be displayed visually as placeholder text, or',
441
- 'text content supplied in a <span> with slot="label", which will also be displayed visually as placeholder text.'
442
- ]
443
- }
444
- );
445
- }
446
- });
447
- }
448
- super.update(changes);
449
- }
450
- bindButtonKeydownListener() {
451
- this.button.addEventListener("keydown", this.handleKeydown);
452
- }
453
- updated(changes) {
454
- super.updated(changes);
455
- if (changes.has("open")) {
456
- this.strategy.open = this.open;
457
- }
458
- }
459
- firstUpdated(changes) {
460
- super.firstUpdated(changes);
461
- this.bindButtonKeydownListener();
462
- this.bindEvents();
463
- }
464
- get dismissHelper() {
465
- return html`
466
- <div class="visually-hidden">
467
- <button
468
- tabindex="-1"
469
- aria-label="Dismiss"
470
- @click=${this.close}
471
- ></button>
472
- </div>
473
- `;
474
- }
475
- renderContainer(menu) {
476
- const accessibleMenu = html`
477
- ${this.dismissHelper} ${menu} ${this.dismissHelper}
478
- `;
479
- if (this.isMobile.matches) {
480
- this.dependencyManager.add("sp-tray");
481
- import("@spectrum-web-components/tray/sp-tray.js");
482
- return html`
483
- <sp-tray
484
- id="popover"
485
- role="presentation"
486
- style=${styleMap(this.containerStyles)}
487
- >
488
- ${accessibleMenu}
489
- </sp-tray>
490
- `;
491
- }
492
- this.dependencyManager.add("sp-popover");
493
- import("@spectrum-web-components/popover/sp-popover.js");
494
- return html`
495
- <sp-popover
496
- id="popover"
497
- role="presentation"
498
- style=${styleMap(this.containerStyles)}
499
- placement=${this.placement}
500
- >
501
- ${accessibleMenu}
502
- </sp-popover>
503
- `;
504
- }
505
- onScroll() {
506
- this.dispatchEvent(
507
- new Event("scroll", {
508
- cancelable: true,
509
- composed: true
510
- })
511
- );
512
- }
513
- get renderMenu() {
514
- const menu = html`
515
- <sp-menu
516
- aria-labelledby="applied-label"
517
- @change=${this.handleChange}
518
- id="menu"
519
- @keydown=${{
520
- handleEvent: this.handleEnterKeydown,
521
- capture: true
522
- }}
523
- @scroll=${this.onScroll}
524
- role=${this.listRole}
525
- .selects=${this.selects}
526
- .selected=${this.value ? [this.value] : []}
527
- size=${this.size}
528
- @sp-menu-item-added-or-updated=${this.shouldManageSelection}
529
- >
530
- <slot @slotchange=${this.shouldScheduleManageSelection}></slot>
531
- </sp-menu>
532
- `;
533
- this.hasRenderedOverlay = this.hasRenderedOverlay || this.focused || this.open || !!this.deprecatedMenu;
534
- if (this.hasRenderedOverlay) {
535
- if (this.dependencyManager.loaded) {
536
- this.dependencyManager.add("sp-overlay");
537
- }
538
- return this.renderOverlay(menu);
539
- }
540
- return menu;
541
- }
542
- shouldScheduleManageSelection(event) {
543
- if (!this.willManageSelection && (!event || event.target.getRootNode().host === this)) {
544
- this.willManageSelection = true;
545
- requestAnimationFrame(() => {
546
- requestAnimationFrame(() => {
547
- this.manageSelection();
548
- });
549
- });
550
- }
551
- }
552
- shouldManageSelection() {
553
- if (this.willManageSelection) {
554
- return;
555
- }
556
- this.willManageSelection = true;
557
- this.manageSelection();
558
- }
559
- async manageSelection() {
560
- if (this.selects == null) return;
561
- this.selectionPromise = new Promise(
562
- (res) => this.selectionResolver = res
563
- );
564
- let selectedItem;
565
- await this.optionsMenu.updateComplete;
566
- if (this.recentlyConnected) {
567
- await new Promise((res) => requestAnimationFrame(() => res(true)));
568
- this.recentlyConnected = false;
569
- }
570
- this.menuItems.forEach((item) => {
571
- if (this.value === item.value && !item.disabled) {
572
- selectedItem = item;
573
- } else {
574
- item.selected = false;
575
- }
576
- });
577
- if (selectedItem) {
578
- selectedItem.selected = !!this.selects;
579
- this.selectedItem = selectedItem;
580
- } else {
581
- this.value = "";
582
- this.selectedItem = void 0;
583
- }
584
- if (this.open) {
585
- await this.optionsMenu.updateComplete;
586
- this.optionsMenu.updateSelectedItemIndex();
587
- }
588
- this.selectionResolver();
589
- this.willManageSelection = false;
590
- }
591
- async getUpdateComplete() {
592
- const complete = await super.getUpdateComplete();
593
- await this.selectionPromise;
594
- return complete;
595
- }
596
- bindEvents() {
597
- var _a;
598
- (_a = this.strategy) == null ? void 0 : _a.abort();
599
- if (this.isMobile.matches) {
600
- this.strategy = new strategies["mobile"](this.button, this);
601
- } else {
602
- this.strategy = new strategies["desktop"](this.button, this);
603
- }
604
- }
605
- connectedCallback() {
606
- super.connectedCallback();
607
- this.recentlyConnected = this.hasUpdated;
608
- }
609
- disconnectedCallback() {
610
- var _a;
611
- this.close();
612
- (_a = this.strategy) == null ? void 0 : _a.releaseDescription();
613
- super.disconnectedCallback();
614
- }
615
- }
616
- __decorateClass([
617
- state()
618
- ], PickerBase.prototype, "appliedLabel", 2);
619
- __decorateClass([
620
- query("#button")
621
- ], PickerBase.prototype, "button", 2);
622
- __decorateClass([
623
- property({ type: Boolean, reflect: true })
624
- ], PickerBase.prototype, "disabled", 2);
625
- __decorateClass([
626
- property({ type: Boolean, reflect: true })
627
- ], PickerBase.prototype, "focused", 2);
628
- __decorateClass([
629
- property({ type: String, reflect: true })
630
- ], PickerBase.prototype, "icons", 2);
631
- __decorateClass([
632
- property({ type: Boolean, reflect: true })
633
- ], PickerBase.prototype, "invalid", 2);
634
- __decorateClass([
635
- property({ type: Boolean, reflect: true })
636
- ], PickerBase.prototype, "pending", 2);
637
- __decorateClass([
638
- property({ type: String, attribute: "pending-label" })
639
- ], PickerBase.prototype, "pendingLabel", 2);
640
- __decorateClass([
641
- property()
642
- ], PickerBase.prototype, "label", 2);
643
- __decorateClass([
644
- property({ type: Boolean, reflect: true })
645
- ], PickerBase.prototype, "open", 2);
646
- __decorateClass([
647
- property({ type: Boolean, reflect: true })
648
- ], PickerBase.prototype, "readonly", 2);
649
- __decorateClass([
650
- state()
651
- ], PickerBase.prototype, "labelAlignment", 2);
652
- __decorateClass([
653
- query("sp-menu")
654
- ], PickerBase.prototype, "optionsMenu", 2);
655
- __decorateClass([
656
- query("sp-overlay")
657
- ], PickerBase.prototype, "overlayElement", 2);
658
- __decorateClass([
659
- property()
660
- ], PickerBase.prototype, "placement", 2);
661
- __decorateClass([
662
- property({ type: Boolean, reflect: true })
663
- ], PickerBase.prototype, "quiet", 2);
664
- __decorateClass([
665
- property({ type: String })
666
- ], PickerBase.prototype, "value", 2);
667
- __decorateClass([
668
- property({ attribute: false })
669
- ], PickerBase.prototype, "selectedItem", 1);
670
- __decorateClass([
671
- state()
672
- ], PickerBase.prototype, "selectedItemContent", 1);
673
- export class Picker extends PickerBase {
674
- constructor() {
675
- super(...arguments);
676
- this.handleKeydown = (event) => {
677
- const { code } = event;
678
- this.focused = true;
679
- if (!code.startsWith("Arrow") || this.readonly || this.pending) {
680
- return;
681
- }
682
- if (code === "ArrowUp" || code === "ArrowDown") {
683
- this.toggle(true);
684
- event.preventDefault();
685
- return;
686
- }
687
- event.preventDefault();
688
- const selectedIndex = this.selectedItem ? this.menuItems.indexOf(this.selectedItem) : -1;
689
- const nextOffset = selectedIndex < 0 || code === "ArrowRight" ? 1 : -1;
690
- let nextIndex = selectedIndex + nextOffset;
691
- while (this.menuItems[nextIndex] && this.menuItems[nextIndex].disabled) {
692
- nextIndex += nextOffset;
693
- }
694
- if (!this.menuItems[nextIndex] || this.menuItems[nextIndex].disabled) {
695
- return;
696
- }
697
- if (!this.value || nextIndex !== selectedIndex) {
698
- this.setValueFromItem(this.menuItems[nextIndex]);
699
- }
700
- };
701
- }
702
- static get styles() {
703
- return [pickerStyles, chevronStyles, chevronIconOverrides];
704
- }
705
- get containerStyles() {
706
- const styles = super.containerStyles;
707
- if (!this.quiet) {
708
- styles["min-width"] = `${this.offsetWidth}px`;
709
- }
710
- return styles;
711
- }
712
- }
713
- //# sourceMappingURL=Picker.dev.js.map