Skip to content

Commit

Permalink
fix(menu): handle selecting while loading sub items
Browse files Browse the repository at this point in the history
  • Loading branch information
vicgeralds committed Mar 14, 2024
1 parent fa3906f commit 1a40362
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/components/menu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export class Menu {
private searchInput: HTMLLimelInputFieldElement;
private portalId: string;
private triggerElement: HTMLSlotElement;
private selectedMenuItem?: MenuItem;

constructor() {
this.portalId = createRandomString();
Expand Down Expand Up @@ -601,6 +602,7 @@ export class Menu {
selectOnEmptyChildren: boolean = true,
) => {
if (Array.isArray(menuItem?.items) && menuItem.items.length > 0) {
this.selectedMenuItem = menuItem;
this.clearSearch();
this.currentSubMenu = menuItem;
this.navigateMenu.emit(menuItem);
Expand All @@ -610,8 +612,14 @@ export class Menu {
return;
} else if (isFunction(menuItem?.items)) {
const menuLoader = menuItem.items as MenuLoader;
this.selectedMenuItem = menuItem;
this.loadingSubItems = true;
const subItems = await menuLoader(menuItem);

if (this.selectedMenuItem !== menuItem) {
return;
}

menuItem.items = subItems;
this.loadingSubItems = false;

Expand All @@ -630,6 +638,9 @@ export class Menu {
return;
}

this.selectedMenuItem = menuItem;
this.loadingSubItems = false;

this.select.emit(menuItem);
this.open = false;
this.currentSubMenu = null;
Expand Down

0 comments on commit 1a40362

Please sign in to comment.