@spectrum-web-components/picker 0.34.0 → 0.34.1-rc.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/picker",
3
- "version": "0.34.0",
3
+ "version": "0.34.1-rc.0+1647bfed5",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -65,17 +65,17 @@
65
65
  "lit-html"
66
66
  ],
67
67
  "dependencies": {
68
- "@spectrum-web-components/base": "^0.34.0",
69
- "@spectrum-web-components/button": "^0.34.0",
70
- "@spectrum-web-components/icon": "^0.34.0",
71
- "@spectrum-web-components/icons-ui": "^0.34.0",
72
- "@spectrum-web-components/icons-workflow": "^0.34.0",
73
- "@spectrum-web-components/menu": "^0.34.0",
74
- "@spectrum-web-components/overlay": "^0.34.0",
75
- "@spectrum-web-components/popover": "^0.34.0",
76
- "@spectrum-web-components/reactive-controllers": "^0.34.0",
77
- "@spectrum-web-components/shared": "^0.34.0",
78
- "@spectrum-web-components/tray": "^0.34.0"
68
+ "@spectrum-web-components/base": "^0.34.1-rc.0+1647bfed5",
69
+ "@spectrum-web-components/button": "^0.34.1-rc.0+1647bfed5",
70
+ "@spectrum-web-components/icon": "^0.34.1-rc.0+1647bfed5",
71
+ "@spectrum-web-components/icons-ui": "^0.34.1-rc.0+1647bfed5",
72
+ "@spectrum-web-components/icons-workflow": "^0.34.1-rc.0+1647bfed5",
73
+ "@spectrum-web-components/menu": "^0.34.1-rc.0+1647bfed5",
74
+ "@spectrum-web-components/overlay": "^0.34.1-rc.0+1647bfed5",
75
+ "@spectrum-web-components/popover": "^0.34.1-rc.0+1647bfed5",
76
+ "@spectrum-web-components/reactive-controllers": "^0.34.1-rc.0+1647bfed5",
77
+ "@spectrum-web-components/shared": "^0.34.1-rc.0+1647bfed5",
78
+ "@spectrum-web-components/tray": "^0.34.1-rc.0+1647bfed5"
79
79
  },
80
80
  "devDependencies": {
81
81
  "@spectrum-css/picker": "^4.0.15"
@@ -88,5 +88,5 @@
88
88
  "./sync/index.js",
89
89
  "./sync/sp-*.js"
90
90
  ],
91
- "gitHead": "f9b3294d67cdd52b2c36897cdc1c20ceaeb019cf"
91
+ "gitHead": "1647bfed54cb29f3513343cd0d2c2d9e73e1c508"
92
92
  }
package/src/Picker.d.ts CHANGED
@@ -1,22 +1,20 @@
1
1
  import { CSSResultArray, PropertyValues, TemplateResult } from '@spectrum-web-components/base';
2
+ import { StyleInfo } from '@spectrum-web-components/base/src/directives.js';
2
3
  import { Focusable } from '@spectrum-web-components/shared/src/focusable.js';
3
4
  import '@spectrum-web-components/icons-ui/icons/sp-icon-chevron100.js';
4
5
  import '@spectrum-web-components/icons-workflow/icons/sp-icon-alert.js';
6
+ import '@spectrum-web-components/overlay/sp-overlay.js';
5
7
  import '@spectrum-web-components/menu/sp-menu.js';
6
- import type { Menu, MenuItem, MenuItemAddedOrUpdatedEvent, MenuItemChildren, MenuItemRemovedEvent } from '@spectrum-web-components/menu';
8
+ import type { Menu, MenuItem, MenuItemChildren } from '@spectrum-web-components/menu';
7
9
  import '@spectrum-web-components/tray/sp-tray.js';
8
10
  import '@spectrum-web-components/popover/sp-popover.js';
9
- import { OverlayOptions, Placement, TriggerInteractions } from '@spectrum-web-components/overlay';
11
+ import { Placement } from '@spectrum-web-components/overlay';
10
12
  import { MatchMediaController } from '@spectrum-web-components/reactive-controllers/src/MatchMedia.js';
11
13
  declare const PickerBase_base: typeof Focusable & {
12
14
  new (...args: any[]): import("@spectrum-web-components/base").SizedElementInterface;
13
15
  prototype: import("@spectrum-web-components/base").SizedElementInterface;
14
16
  };
15
17
  export declare class PickerBase extends PickerBase_base {
16
- /**
17
- * @private
18
- */
19
- static openOverlay: (target: HTMLElement, interaction: TriggerInteractions, content: HTMLElement, options: OverlayOptions) => Promise<() => void>;
20
18
  protected isMobile: MatchMediaController;
21
19
  appliedLabel?: string;
22
20
  button: HTMLButtonElement;
@@ -29,8 +27,7 @@ export declare class PickerBase extends PickerBase_base {
29
27
  open: boolean;
30
28
  readonly: boolean;
31
29
  selects: undefined | 'single';
32
- menuItems: MenuItem[];
33
- private restoreChildren?;
30
+ get menuItems(): MenuItem[];
34
31
  optionsMenu: Menu;
35
32
  /**
36
33
  * @type {"auto" | "auto-start" | "auto-end" | "top" | "bottom" | "right" | "left" | "top-start" | "top-end" | "bottom-start" | "bottom-end" | "right-start" | "right-end" | "left-start" | "left-end" | "none"}
@@ -39,15 +36,17 @@ export declare class PickerBase extends PickerBase_base {
39
36
  placement: Placement;
40
37
  quiet: boolean;
41
38
  value: string;
42
- selectedItem?: MenuItem;
43
- private closeOverlay?;
44
- private popoverEl;
39
+ get selectedItem(): MenuItem | undefined;
40
+ set selectedItem(selectedItem: MenuItem | undefined);
41
+ _selectedItem?: MenuItem;
45
42
  protected listRole: 'listbox' | 'menu';
46
43
  protected itemRole: string;
47
44
  constructor();
48
45
  get focusElement(): HTMLElement;
49
46
  forceFocusVisible(): void;
50
47
  onButtonBlur(): void;
48
+ private preventNextToggle;
49
+ protected handlePointerdown(): void;
51
50
  protected onButtonClick(): void;
52
51
  focus(options?: FocusOptions): void;
53
52
  onHelperFocus(): void;
@@ -58,35 +57,26 @@ export declare class PickerBase extends PickerBase_base {
58
57
  protected setMenuItemSelected(item: MenuItem, value: boolean): void;
59
58
  toggle(target?: boolean): void;
60
59
  close(): void;
61
- overlayOpenCallback: () => Promise<void>;
62
- overlayCloseCallback: () => Promise<void>;
63
- private popoverFragment;
64
- private generatePopover;
65
- private openMenu;
66
- protected sizePopover(popover: HTMLElement): void;
67
- private closeMenu;
60
+ protected get containerStyles(): StyleInfo;
68
61
  protected get selectedItemContent(): MenuItemChildren;
62
+ protected set selectedItemContent(selectedItemContent: MenuItemChildren | undefined);
63
+ _selectedItemContent?: MenuItemChildren;
69
64
  protected renderLabelContent(content: Node[]): TemplateResult | Node[];
70
65
  protected get buttonContent(): TemplateResult[];
71
66
  applyFocusElementLabel: (value?: string) => void;
67
+ protected get renderOverlay(): TemplateResult;
72
68
  protected render(): TemplateResult;
73
69
  protected update(changes: PropertyValues<this>): void;
74
70
  protected get dismissHelper(): TemplateResult;
75
- protected get renderPopover(): TemplateResult;
76
- private _willUpdateItems;
77
- protected itemsUpdated: Promise<void>;
78
- /**
79
- * Acquire the available MenuItems in the Picker by
80
- * direct element query or by assuming the list managed
81
- * by the Menu within the open options overlay.
82
- */
83
- protected updateMenuItems(event?: MenuItemAddedOrUpdatedEvent | MenuItemRemovedEvent): void;
71
+ protected get renderContainer(): TemplateResult;
72
+ private willManageSelection;
73
+ protected shouldScheduleManageSelection(event?: Event): void;
74
+ protected shouldManageSelection(): void;
84
75
  protected manageSelection(): Promise<void>;
85
- private menuStatePromise;
86
- private menuStateResolver;
87
76
  private selectionPromise;
88
77
  private selectionResolver;
89
78
  protected getUpdateComplete(): Promise<boolean>;
79
+ private recentlyConnected;
90
80
  connectedCallback(): void;
91
81
  disconnectedCallback(): void;
92
82
  }
@@ -101,7 +91,7 @@ export declare class PickerBase extends PickerBase_base {
101
91
  */
102
92
  export declare class Picker extends PickerBase {
103
93
  static get styles(): CSSResultArray;
104
- protected sizePopover(popover: HTMLElement): void;
94
+ protected get containerStyles(): StyleInfo;
105
95
  protected onKeydown: (event: KeyboardEvent) => void;
106
96
  }
107
97
  export {};
package/src/Picker.dev.js CHANGED
@@ -13,12 +13,12 @@ var __decorateClass = (decorators, target, key, kind) => {
13
13
  import {
14
14
  html,
15
15
  nothing,
16
- render,
17
16
  SizedMixin
18
17
  } from "@spectrum-web-components/base";
19
18
  import {
20
19
  classMap,
21
- ifDefined
20
+ ifDefined,
21
+ styleMap
22
22
  } from "@spectrum-web-components/base/src/directives.js";
23
23
  import {
24
24
  property,
@@ -28,15 +28,12 @@ import {
28
28
  import pickerStyles from "./picker.css.js";
29
29
  import chevronStyles from "@spectrum-web-components/icon/src/spectrum-icon-chevron.css.js";
30
30
  import { Focusable } from "@spectrum-web-components/shared/src/focusable.js";
31
- import { reparentChildren } from "@spectrum-web-components/shared/src/reparent-children.js";
32
31
  import "@spectrum-web-components/icons-ui/icons/sp-icon-chevron100.js";
33
32
  import "@spectrum-web-components/icons-workflow/icons/sp-icon-alert.js";
33
+ import "@spectrum-web-components/overlay/sp-overlay.js";
34
34
  import "@spectrum-web-components/menu/sp-menu.js";
35
35
  import "@spectrum-web-components/tray/sp-tray.js";
36
36
  import "@spectrum-web-components/popover/sp-popover.js";
37
- import {
38
- openOverlay
39
- } from "@spectrum-web-components/overlay";
40
37
  import {
41
38
  IS_MOBILE,
42
39
  MatchMediaController
@@ -57,12 +54,12 @@ export class PickerBase extends SizedMixin(Focusable) {
57
54
  this.open = false;
58
55
  this.readonly = false;
59
56
  this.selects = "single";
60
- this.menuItems = [];
61
57
  this.placement = "bottom-start";
62
58
  this.quiet = false;
63
59
  this.value = "";
64
60
  this.listRole = "listbox";
65
61
  this.itemRole = "option";
62
+ this.preventNextToggle = false;
66
63
  this.onKeydown = (event) => {
67
64
  this.focused = true;
68
65
  if (event.code !== "ArrowDown" && event.code !== "ArrowUp") {
@@ -71,32 +68,37 @@ export class PickerBase extends SizedMixin(Focusable) {
71
68
  event.preventDefault();
72
69
  this.toggle(true);
73
70
  };
74
- this.overlayOpenCallback = async () => {
75
- this.updateMenuItems();
76
- await this.itemsUpdated;
77
- await this.optionsMenu.updateComplete;
78
- requestAnimationFrame(() => this.menuStateResolver());
79
- };
80
- this.overlayCloseCallback = async () => {
81
- if (this.restoreChildren) {
82
- this.restoreChildren();
83
- this.restoreChildren = void 0;
84
- }
85
- this.close();
86
- requestAnimationFrame(() => this.menuStateResolver());
87
- };
88
71
  this.applyFocusElementLabel = (value) => {
89
72
  this.appliedLabel = value;
90
73
  };
91
- this._willUpdateItems = false;
92
- this.itemsUpdated = Promise.resolve();
93
- this.menuStatePromise = Promise.resolve();
74
+ this.willManageSelection = false;
94
75
  this.selectionPromise = Promise.resolve();
76
+ this.recentlyConnected = false;
95
77
  this.onKeydown = this.onKeydown.bind(this);
78
+ this.addEventListener("focusout", (event) => {
79
+ if (event.relatedTarget && this.contains(event.relatedTarget) || event.target !== this) {
80
+ return;
81
+ }
82
+ this.open = false;
83
+ });
96
84
  }
97
85
  get target() {
98
86
  return this.button;
99
87
  }
88
+ get menuItems() {
89
+ return this.optionsMenu.childItems;
90
+ }
91
+ get selectedItem() {
92
+ return this._selectedItem;
93
+ }
94
+ set selectedItem(selectedItem) {
95
+ this.selectedItemContent = selectedItem ? selectedItem.itemChildren : void 0;
96
+ if (selectedItem === this.selectedItem)
97
+ return;
98
+ const oldSelectedItem = this.selectedItem;
99
+ this._selectedItem = selectedItem;
100
+ this.requestUpdate("selectedItem", oldSelectedItem);
101
+ }
100
102
  get focusElement() {
101
103
  if (this.open) {
102
104
  return this.optionsMenu;
@@ -113,8 +115,14 @@ export class PickerBase extends SizedMixin(Focusable) {
113
115
  this.onKeydown
114
116
  );
115
117
  }
118
+ handlePointerdown() {
119
+ this.preventNextToggle = this.open;
120
+ }
116
121
  onButtonClick() {
117
- this.toggle();
122
+ if (!this.preventNextToggle) {
123
+ this.toggle();
124
+ }
125
+ this.preventNextToggle = false;
118
126
  }
119
127
  focus(options) {
120
128
  super.focus(options);
@@ -135,20 +143,22 @@ export class PickerBase extends SizedMixin(Focusable) {
135
143
  handleChange(event) {
136
144
  const target = event.target;
137
145
  const [selected] = target.selectedItems;
146
+ event.stopPropagation();
138
147
  if (event.cancelable) {
139
- event.stopPropagation();
140
148
  this.setValueFromItem(selected, event);
141
149
  } else {
142
150
  this.open = false;
143
151
  }
144
152
  }
145
153
  async setValueFromItem(item, menuChangeEvent) {
154
+ this.open = false;
146
155
  const oldSelectedItem = this.selectedItem;
147
156
  const oldValue = this.value;
148
- this.selectedItem = item;
149
- this.value = item.value;
150
- this.open = false;
151
- await this.updateComplete;
157
+ if (this.selects) {
158
+ this.selectedItem = item;
159
+ this.value = item.value;
160
+ await this.updateComplete;
161
+ }
152
162
  const applyDefault = this.dispatchEvent(
153
163
  new Event("change", {
154
164
  bubbles: true,
@@ -156,7 +166,7 @@ export class PickerBase extends SizedMixin(Focusable) {
156
166
  composed: true
157
167
  })
158
168
  );
159
- if (!applyDefault) {
169
+ if (!applyDefault && this.selects) {
160
170
  if (menuChangeEvent) {
161
171
  menuChangeEvent.preventDefault();
162
172
  }
@@ -191,74 +201,23 @@ export class PickerBase extends SizedMixin(Focusable) {
191
201
  }
192
202
  this.open = false;
193
203
  }
194
- async generatePopover() {
195
- if (!this.popoverFragment) {
196
- this.popoverFragment = document.createDocumentFragment();
197
- }
198
- render(this.renderPopover, this.popoverFragment, { host: this });
199
- this.popoverEl = this.popoverFragment.children[0];
200
- this.optionsMenu = this.popoverEl.children[1];
201
- }
202
- async openMenu() {
203
- let reparentableChildren = [];
204
- const deprecatedMenu = this.querySelector(":scope > sp-menu");
205
- await this.generatePopover();
206
- if (deprecatedMenu) {
207
- reparentableChildren = Array.from(deprecatedMenu.children);
208
- } else {
209
- reparentableChildren = Array.from(this.children).filter(
210
- (element) => {
211
- return !element.hasAttribute("slot");
212
- }
213
- );
214
- }
215
- if (reparentableChildren.length === 0) {
216
- this.menuStateResolver();
217
- return;
218
- }
219
- this.restoreChildren = reparentChildren(reparentableChildren, this.optionsMenu, {
220
- position: "beforeend",
221
- prepareCallback: (el) => {
222
- if (this.value === el.value) {
223
- this.setMenuItemSelected(el, true);
224
- }
225
- return (el2) => {
226
- if (typeof el2.focused !== "undefined") {
227
- el2.focused = false;
228
- }
229
- };
230
- }
231
- });
232
- this.sizePopover(this.popoverEl);
233
- if (true) {
234
- window.__swc.ignoreWarningLevels.deprecation = true;
235
- }
236
- this.closeOverlay = Picker.openOverlay(this, "modal", this.popoverEl, {
237
- placement: this.isMobile.matches ? "none" : this.placement,
238
- receivesFocus: "auto"
239
- });
240
- if (true) {
241
- window.__swc.ignoreWarningLevels.deprecation = false;
242
- }
243
- }
244
- sizePopover(popover) {
204
+ get containerStyles() {
245
205
  if (this.isMobile.matches) {
246
- popover.style.setProperty("--swc-menu-width", `100%`);
247
- return;
248
- }
249
- }
250
- async closeMenu() {
251
- if (this.closeOverlay) {
252
- const closeOverlay = this.closeOverlay;
253
- delete this.closeOverlay;
254
- (await closeOverlay)();
206
+ return {
207
+ "--swc-menu-width": "100%"
208
+ };
255
209
  }
210
+ return {};
256
211
  }
257
212
  get selectedItemContent() {
258
- if (this.selectedItem) {
259
- return this.selectedItem.itemChildren;
260
- }
261
- return { icon: [], content: [] };
213
+ return this._selectedItemContent || { icon: [], content: [] };
214
+ }
215
+ set selectedItemContent(selectedItemContent) {
216
+ if (selectedItemContent === this.selectedItemContent)
217
+ return;
218
+ const oldContent = this.selectedItemContent;
219
+ this._selectedItemContent = selectedItemContent;
220
+ this.requestUpdate("selectedItemContent", oldContent);
262
221
  }
263
222
  renderLabelContent(content) {
264
223
  if (this.value && this.selectedItem) {
@@ -316,13 +275,37 @@ export class PickerBase extends SizedMixin(Focusable) {
316
275
  `
317
276
  ];
318
277
  }
278
+ get renderOverlay() {
279
+ return html`
280
+ <sp-overlay
281
+ .triggerElement=${this}
282
+ .offset=${0}
283
+ ?open=${this.open}
284
+ .placement=${this.placement}
285
+ type="auto"
286
+ .receivesFocus=${"true"}
287
+ @beforetoggle=${(event) => {
288
+ if (event.composedPath()[0] !== event.target) {
289
+ return;
290
+ }
291
+ this.open = event.newState === "open";
292
+ if (!this.open) {
293
+ this.optionsMenu.updateSelectedItemIndex();
294
+ this.optionsMenu.closeDescendentOverlays();
295
+ }
296
+ }}
297
+ >
298
+ ${this.renderContainer}
299
+ </sp-overlay>
300
+ `;
301
+ }
319
302
  // a helper to throw focus to the button is needed because Safari
320
303
  // won't include buttons in the tab order even with tabindex="0"
321
304
  render() {
322
305
  return html`
323
306
  <span
324
307
  id="focus-helper"
325
- tabindex="${this.focused ? "-1" : "0"}"
308
+ tabindex="${this.focused || this.open ? "-1" : "0"}"
326
309
  @focus=${this.onHelperFocus}
327
310
  ></span>
328
311
  <button
@@ -335,11 +318,13 @@ export class PickerBase extends SizedMixin(Focusable) {
335
318
  @blur=${this.onButtonBlur}
336
319
  @click=${this.onButtonClick}
337
320
  @focus=${this.onButtonFocus}
321
+ @pointerdown=${this.handlePointerdown}
338
322
  ?disabled=${this.disabled}
339
323
  tabindex="-1"
340
324
  >
341
325
  ${this.buttonContent}
342
326
  </button>
327
+ ${this.renderOverlay}
343
328
  `;
344
329
  }
345
330
  update(changes) {
@@ -349,21 +334,15 @@ export class PickerBase extends SizedMixin(Focusable) {
349
334
  if (changes.has("disabled") && this.disabled) {
350
335
  this.open = false;
351
336
  }
352
- if (changes.has("open") && (this.open || typeof changes.get("open") !== "undefined")) {
353
- this.menuStatePromise = new Promise(
354
- (res) => this.menuStateResolver = res
355
- );
356
- if (this.open) {
357
- this.openMenu();
358
- } else {
359
- this.closeMenu();
360
- }
337
+ if (changes.has("value")) {
338
+ this.shouldScheduleManageSelection();
361
339
  }
362
- if (changes.has("value") && !changes.has("selectedItem")) {
363
- this.updateMenuItems();
340
+ if (!this.hasUpdated) {
341
+ const deprecatedMenu = this.querySelector(":scope > sp-menu");
342
+ deprecatedMenu == null ? void 0 : deprecatedMenu.setAttribute("selects", "inherit");
364
343
  }
365
344
  if (true) {
366
- if (!this.hasUpdated && this.querySelector("sp-menu")) {
345
+ if (!this.hasUpdated && this.querySelector(":scope > sp-menu")) {
367
346
  const { localName } = this;
368
347
  window.__swc.warn(
369
348
  this,
@@ -386,7 +365,7 @@ export class PickerBase extends SizedMixin(Focusable) {
386
365
  </div>
387
366
  `;
388
367
  }
389
- get renderPopover() {
368
+ get renderContainer() {
390
369
  const content = html`
391
370
  ${this.dismissHelper}
392
371
  <sp-menu
@@ -394,7 +373,11 @@ export class PickerBase extends SizedMixin(Focusable) {
394
373
  role="${this.listRole}"
395
374
  @change=${this.handleChange}
396
375
  .selects=${this.selects}
397
- ></sp-menu>
376
+ .selected=${this.value ? [this.value] : []}
377
+ @sp-menu-item-added-or-updated=${this.shouldManageSelection}
378
+ >
379
+ <slot @slotchange=${this.shouldScheduleManageSelection}></slot>
380
+ </sp-menu>
398
381
  ${this.dismissHelper}
399
382
  `;
400
383
  if (this.isMobile.matches) {
@@ -402,9 +385,7 @@ export class PickerBase extends SizedMixin(Focusable) {
402
385
  <sp-tray
403
386
  id="popover"
404
387
  role="presentation"
405
- @sp-menu-item-added-or-updated=${this.updateMenuItems}
406
- .overlayOpenCallback=${this.overlayOpenCallback}
407
- .overlayCloseCallback=${this.overlayCloseCallback}
388
+ style=${styleMap(this.containerStyles)}
408
389
  >
409
390
  ${content}
410
391
  </sp-tray>
@@ -414,56 +395,42 @@ export class PickerBase extends SizedMixin(Focusable) {
414
395
  <sp-popover
415
396
  id="popover"
416
397
  role="presentation"
417
- @sp-menu-item-added-or-updated=${this.updateMenuItems}
418
- .overlayOpenCallback=${this.overlayOpenCallback}
419
- .overlayCloseCallback=${this.overlayCloseCallback}
398
+ style=${styleMap(this.containerStyles)}
399
+ placement=${this.placement}
420
400
  >
421
401
  ${content}
422
402
  </sp-popover>
423
403
  `;
424
404
  }
425
- /**
426
- * Acquire the available MenuItems in the Picker by
427
- * direct element query or by assuming the list managed
428
- * by the Menu within the open options overlay.
429
- */
430
- updateMenuItems(event) {
431
- if (this.open && (event == null ? void 0 : event.type) === "sp-menu-item-removed")
432
- return;
433
- if (this._willUpdateItems)
434
- return;
435
- this._willUpdateItems = true;
436
- if ((event == null ? void 0 : event.item) === this.selectedItem) {
437
- this.requestUpdate();
405
+ shouldScheduleManageSelection(event) {
406
+ if (!this.willManageSelection && (!event || event.target.getRootNode().host === this)) {
407
+ this.willManageSelection = true;
408
+ requestAnimationFrame(() => {
409
+ requestAnimationFrame(() => {
410
+ this.manageSelection();
411
+ });
412
+ });
438
413
  }
439
- let resolve = () => {
414
+ }
415
+ shouldManageSelection() {
416
+ if (this.willManageSelection) {
440
417
  return;
441
- };
442
- this.itemsUpdated = new Promise((res) => resolve = res);
443
- window.requestAnimationFrame(async () => {
444
- if (this.open) {
445
- await this.optionsMenu.updateComplete;
446
- this.menuItems = this.optionsMenu.childItems;
447
- } else {
448
- this.menuItems = [
449
- ...this.querySelectorAll(
450
- 'sp-menu-item:not([slot="submenu"] *)'
451
- )
452
- ];
453
- }
454
- this.manageSelection();
455
- resolve();
456
- this._willUpdateItems = false;
457
- });
418
+ }
419
+ this.willManageSelection = true;
420
+ this.manageSelection();
458
421
  }
459
422
  async manageSelection() {
460
423
  if (this.selects == null)
461
424
  return;
462
- await this.menuStatePromise;
463
425
  this.selectionPromise = new Promise(
464
426
  (res) => this.selectionResolver = res
465
427
  );
466
428
  let selectedItem;
429
+ await this.optionsMenu.updateComplete;
430
+ if (this.recentlyConnected) {
431
+ await new Promise((res) => requestAnimationFrame(() => res(true)));
432
+ this.recentlyConnected = false;
433
+ }
467
434
  this.menuItems.forEach((item) => {
468
435
  if (this.value === item.value && !item.disabled) {
469
436
  selectedItem = item;
@@ -483,34 +450,22 @@ export class PickerBase extends SizedMixin(Focusable) {
483
450
  this.optionsMenu.updateSelectedItemIndex();
484
451
  }
485
452
  this.selectionResolver();
453
+ this.willManageSelection = false;
486
454
  }
487
455
  async getUpdateComplete() {
488
456
  const complete = await super.getUpdateComplete();
489
- await this.menuStatePromise;
490
- await this.itemsUpdated;
491
457
  await this.selectionPromise;
492
458
  return complete;
493
459
  }
494
460
  connectedCallback() {
495
- this.updateMenuItems();
496
- this.addEventListener(
497
- "sp-menu-item-added-or-updated",
498
- this.updateMenuItems
499
- );
500
- this.addEventListener("sp-menu-item-removed", this.updateMenuItems);
501
461
  super.connectedCallback();
462
+ this.recentlyConnected = this.hasUpdated;
502
463
  }
503
464
  disconnectedCallback() {
504
465
  this.close();
505
466
  super.disconnectedCallback();
506
467
  }
507
468
  }
508
- /**
509
- * @private
510
- */
511
- PickerBase.openOverlay = async (target, interaction, content, options) => {
512
- return await openOverlay(target, interaction, content, options);
513
- };
514
469
  __decorateClass([
515
470
  state()
516
471
  ], PickerBase.prototype, "appliedLabel", 2);
@@ -538,6 +493,9 @@ __decorateClass([
538
493
  __decorateClass([
539
494
  property({ type: Boolean, reflect: true })
540
495
  ], PickerBase.prototype, "readonly", 2);
496
+ __decorateClass([
497
+ query("sp-menu")
498
+ ], PickerBase.prototype, "optionsMenu", 2);
541
499
  __decorateClass([
542
500
  property()
543
501
  ], PickerBase.prototype, "placement", 2);
@@ -549,7 +507,10 @@ __decorateClass([
549
507
  ], PickerBase.prototype, "value", 2);
550
508
  __decorateClass([
551
509
  property({ attribute: false })
552
- ], PickerBase.prototype, "selectedItem", 2);
510
+ ], PickerBase.prototype, "selectedItem", 1);
511
+ __decorateClass([
512
+ property({ attribute: false })
513
+ ], PickerBase.prototype, "selectedItemContent", 1);
553
514
  export class Picker extends PickerBase {
554
515
  constructor() {
555
516
  super(...arguments);
@@ -581,11 +542,12 @@ export class Picker extends PickerBase {
581
542
  static get styles() {
582
543
  return [pickerStyles, chevronStyles];
583
544
  }
584
- sizePopover(popover) {
585
- super.sizePopover(popover);
586
- if (this.quiet)
587
- return;
588
- popover.style.setProperty("min-width", `${this.offsetWidth}px`);
545
+ get containerStyles() {
546
+ const styles = super.containerStyles;
547
+ if (!this.quiet) {
548
+ styles["min-width"] = `${this.offsetWidth}px`;
549
+ }
550
+ return styles;
589
551
  }
590
552
  }
591
553
  //# sourceMappingURL=Picker.dev.js.map