Skip to content

Commit

Permalink
fix(menu-flyout): properly close sublists #712, #1122
Browse files Browse the repository at this point in the history
  • Loading branch information
Arturo committed Jul 8, 2022
1 parent 077633b commit af95d17
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/components/src/components/menu-flyout/menu-flyout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,30 @@ export class MenuFlyout {

private trigger: HTMLElement;
private lists: Set<HTMLScaleMenuFlyoutListElement> = new Set();
// Keep track of the current active/open list
private activeList: HTMLScaleMenuFlyoutListElement;

@Listen('scale-open')
async handleScaleOpen({ detail }) {
// Close the previous active list and its parents if
// - it's not the root and
// - it's not the one being opened
// (useful only with "click" interactions)
const rootList = this.getListElement();
if (
this.activeList &&
this.activeList.active &&
this.activeList !== rootList &&
this.activeList !== detail.list
) {
let list: HTMLScaleMenuFlyoutListElement = this.activeList;
while (list != null && list !== rootList) {
await list.close(true);
list = list.parentElement.closest(MENU_SELECTOR);
}
}
this.activeList = detail.list;
}

@Listen('scale-select')
handleScaleSelect({ detail }) {
Expand Down

0 comments on commit af95d17

Please sign in to comment.