Skip to content

Commit 01a7e35

Browse files
adixon-adobeWestbrook
authored andcommitted
fix: issues with optionsMenu & menuItems
The @query wasn't working here -- ended up with null deference errors. Also need to initialize menuItems in firstUpdated in case the menu state is already open. Also revert an aria-role change that shouldn't have been committed. Bad late-night flawgic.
1 parent b7e67a1 commit 01a7e35

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

packages/picker/src/Picker.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ export class PickerBase extends SizedMixin(Focusable) {
9797
public menuItems: MenuItem[] = [];
9898
private restoreChildren?: Function;
9999

100-
@query('sp-menu', true) // important to cache since this can get reparented
101100
public optionsMenu!: Menu;
102101

103102
/**
@@ -350,14 +349,25 @@ export class PickerBase extends SizedMixin(Focusable) {
350349
@click=${this.onClick}
351350
@sp-overlay-closed=${this.onOverlayClosed}
352351
>
353-
<sp-menu id="menu" aria-role="${this.listRole}"></sp-menu>
352+
<sp-menu id="menu" role="${this.listRole}"></sp-menu>
354353
</sp-popover>
355354
`;
356355
}
357356

357+
protected updateMenuItems(): void {
358+
this.menuItems = [
359+
...this.querySelectorAll(`sp-menu-item`),
360+
] as MenuItem[];
361+
}
362+
358363
protected firstUpdated(changedProperties: PropertyValues): void {
359364
super.firstUpdated(changedProperties);
360365

366+
// Since the sp-menu gets reparented by the popover, initialize it here
367+
this.optionsMenu = this.shadowRoot.querySelector('sp-menu') as Menu;
368+
369+
this.updateMenuItems();
370+
361371
const deprecatedMenu = this.querySelector('sp-menu');
362372
if (deprecatedMenu) {
363373
console.warn(
@@ -427,9 +437,7 @@ export class PickerBase extends SizedMixin(Focusable) {
427437

428438
public connectedCallback(): void {
429439
if (!this.open) {
430-
this.menuItems = [
431-
...this.querySelectorAll(`sp-menu-item`),
432-
] as MenuItem[];
440+
this.updateMenuItems();
433441
}
434442
super.connectedCallback();
435443
}

0 commit comments

Comments
 (0)