octicon-rss(16/)
You've already forked ionic-framework
mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-10 22:44:13 +08:00
fix(menu): wait until all menus are ready
fixes #15727
This commit is contained in:
octicon-git-branch(16/)
octicon-tag(16/)
octicon-diff(16/tw-mr-1) 3 changed files with 21 additions and 8 deletions
@@ -16,6 +16,7 @@ export class MenuController implements MenuControllerI {
|
||||
private menuAnimations = new Map<string, AnimationBuilder>();
|
||||
|
||||
@Prop({ connect: 'ion-animation-controller' }) animationCtrl!: HTMLIonAnimationControllerElement;
|
||||
@Prop({ context: 'document' }) doc!: Document;
|
||||
|
||||
constructor() {
|
||||
this.registerAnimation('reveal', menuRevealAnimation);
|
||||
@@ -134,6 +135,8 @@ export class MenuController implements MenuControllerI {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
await this.waitUntilReady();
|
||||
|
||||
if (menuId === 'start' || menuId === 'end') {
|
||||
// there could be more than one menu on the same side
|
||||
// so first try to get the enabled one
|
||||
@@ -166,24 +169,27 @@ export class MenuController implements MenuControllerI {
|
||||
* Returns the instance of the menu already opened, otherwise `null`.
|
||||
*/
|
||||
@Method()
|
||||
getOpen(): Promise<HTMLIonMenuElement | undefined> {
|
||||
return Promise.resolve(this.getOpenSync());
|
||||
async getOpen(): Promise<HTMLIonMenuElement | undefined> {
|
||||
await this.waitUntilReady();
|
||||
return this.getOpenSync();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all menu instances.
|
||||
*/
|
||||
@Method()
|
||||
getMenus(): Promise<HTMLIonMenuElement[]> {
|
||||
return Promise.resolve(this.getMenusSync());
|
||||
async getMenus(): Promise<HTMLIonMenuElement[]> {
|
||||
await this.waitUntilReady();
|
||||
return this.getMenusSync();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if any menu is currently animating.
|
||||
*/
|
||||
@Method()
|
||||
isAnimating(): Promise<boolean> {
|
||||
return Promise.resolve(this.isAnimatingSync());
|
||||
async isAnimating(): Promise<boolean> {
|
||||
await this.waitUntilReady();
|
||||
return this.isAnimatingSync();
|
||||
}
|
||||
|
||||
@Method()
|
||||
@@ -264,4 +270,11 @@ export class MenuController implements MenuControllerI {
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private waitUntilReady() {
|
||||
return Promise.all(
|
||||
Array.from(this.doc.querySelectorAll('ion-menu'))
|
||||
.map(menu => menu.componentOnReady())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ export interface MenuControllerI {
|
||||
_unregister(menu: MenuI): void;
|
||||
_setActiveMenu(menu: MenuI): void;
|
||||
|
||||
getMenusSync(): HTMLIonMenuElement[];
|
||||
getMenus(): Promise<HTMLIonMenuElement[]>;
|
||||
getOpenSync(): HTMLIonMenuElement | undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@ export class Menu implements ComponentInterface, MenuI {
|
||||
|
||||
let isEnabled = !this.disabled;
|
||||
if (isEnabled) {
|
||||
const menus = this.menuCtrl!.getMenusSync();
|
||||
const menus = await this.menuCtrl!.getMenus();
|
||||
isEnabled = !menus.some((m: any) => {
|
||||
return m.side === this.side && !m.disabled;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user