@spectrum-web-components/picker 0.31.1-react.3 → 0.32.1-overlay.33

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