Skip to content

Commit

Permalink
fix: issues with optionsMenu & menuItems
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
adixon-adobe authored and Westbrook committed Mar 9, 2021
1 parent b7e67a1 commit 01a7e35
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/picker/src/Picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export class PickerBase extends SizedMixin(Focusable) {
public menuItems: MenuItem[] = [];
private restoreChildren?: Function;

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

/**
Expand Down Expand Up @@ -350,14 +349,25 @@ export class PickerBase extends SizedMixin(Focusable) {
@click=${this.onClick}
@sp-overlay-closed=${this.onOverlayClosed}
>
<sp-menu id="menu" aria-role="${this.listRole}"></sp-menu>
<sp-menu id="menu" role="${this.listRole}"></sp-menu>
</sp-popover>
`;
}

protected updateMenuItems(): void {
this.menuItems = [
...this.querySelectorAll(`sp-menu-item`),
] as MenuItem[];
}

protected firstUpdated(changedProperties: PropertyValues): void {
super.firstUpdated(changedProperties);

// Since the sp-menu gets reparented by the popover, initialize it here
this.optionsMenu = this.shadowRoot.querySelector('sp-menu') as Menu;

this.updateMenuItems();

const deprecatedMenu = this.querySelector('sp-menu');
if (deprecatedMenu) {
console.warn(
Expand Down Expand Up @@ -427,9 +437,7 @@ export class PickerBase extends SizedMixin(Focusable) {

public connectedCallback(): void {
if (!this.open) {
this.menuItems = [
...this.querySelectorAll(`sp-menu-item`),
] as MenuItem[];
this.updateMenuItems();
}
super.connectedCallback();
}
Expand Down

0 comments on commit 01a7e35

Please sign in to comment.