diff --git a/src/components/menu/menu-controller.ts b/src/components/menu/menu-controller.ts index b24245f932..aa4a0bebad 100644 --- a/src/components/menu/menu-controller.ts +++ b/src/components/menu/menu-controller.ts @@ -125,8 +125,8 @@ export class MenuController { * @return {Promise} returns a promise when the menu is fully opened */ open(menuId?: string): Promise { - let menu = this.get(menuId); - if (menu) { + const menu = this.get(menuId); + if (menu && !this.isAnimating()) { let openedMenu = this.getOpen(); if (openedMenu && menu !== openedMenu) { openedMenu.setOpen(false, false); @@ -171,9 +171,9 @@ export class MenuController { * @return {Promise} returns a promise when the menu has been toggled */ toggle(menuId?: string): Promise { - let menu = this.get(menuId); - if (menu) { - let openedMenu = this.getOpen(); + const menu = this.get(menuId); + if (menu && !this.isAnimating()) { + var openedMenu = this.getOpen(); if (openedMenu && menu !== openedMenu) { openedMenu.setOpen(false, false); } @@ -191,7 +191,7 @@ export class MenuController { * @return {Menu} Returns the instance of the menu, which is useful for chaining. */ enable(shouldEnable: boolean, menuId?: string): Menu { - let menu = this.get(menuId); + const menu = this.get(menuId); if (menu) { return menu.enable(shouldEnable); } @@ -204,7 +204,7 @@ export class MenuController { * @return {Menu} Returns the instance of the menu, which is useful for chaining. */ swipeEnable(shouldEnable: boolean, menuId?: string): Menu { - let menu = this.get(menuId); + const menu = this.get(menuId); if (menu) { return menu.swipeEnable(shouldEnable); } @@ -229,7 +229,7 @@ export class MenuController { * @return {boolean} Returns true if the menu is currently enabled, otherwise false. */ isEnabled(menuId?: string): boolean { - let menu = this.get(menuId); + const menu = this.get(menuId); return menu && menu.enabled || false; } @@ -278,7 +278,6 @@ export class MenuController { return this._menus.find(m => m.isOpen); } - /** * @return {Array} Returns an array of all menu instances. */ @@ -286,6 +285,14 @@ export class MenuController { return this._menus; } + /** + * @private + * @return {boolean} if any menu is currently animating + */ + isAnimating(): boolean { + return this._menus.some(menu => menu.isAnimating()); + } + /** * @private */ diff --git a/src/components/menu/menu.ts b/src/components/menu/menu.ts index d9347ac5c5..fdb4d29f2f 100644 --- a/src/components/menu/menu.ts +++ b/src/components/menu/menu.ts @@ -412,7 +412,7 @@ export class Menu { setOpen(shouldOpen: boolean, animated: boolean = true): Promise { // _isPrevented is used to prevent unwanted opening/closing after swiping open/close // or swiping open the menu while pressing down on the MenuToggle button - if ((shouldOpen && this.isOpen) || !this._isEnabled || this._isAnimating) { + if ((shouldOpen === this.isOpen) || !this._isEnabled || this._isAnimating) { return Promise.resolve(this.isOpen); } @@ -436,6 +436,13 @@ export class Menu { this._app.isEnabled(); } + /** + * @private + */ + isAnimating(): boolean { + return this._isAnimating; + } + _swipeBeforeStart() { if (!this.canSwipe()) { assert(false, 'canSwipe() has to be true');