question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: unable to control IonMenu programmatically using MenuController

See original GitHub issue

Prerequisites

Ionic Framework Version

  • v4.x
  • v5.x
  • v6.x

Current Behavior

When I try to programmatically toggle ion-menu using await menuController.toggle(menuId), menu does not open.

Expected Behavior

In previous versions of Ionic (5.9.3) calling toggle on menuController opened the menu correctly - see my other branch https://github.com/nika1001/ionic6-menu-controller-issue/tree/ionic5-working-menu I would like to have the same behavior also in Ionic6.

Steps to Reproduce

  1. Start an application provided in the github: https://github.com/nika1001/ionic6-menu-controller-issue
  2. Pressing buttons under “Toggle menu by MenuController” header does nothing

Code Reproduction URL

https://github.com/nika1001/ionic6-menu-controller-issue

Ionic Info

Ionic:

Ionic CLI : 6.18.1 (C:\Tools\nvm\v16.10.0\node_modules@ionic\cli) Ionic Framework : @ionic/react 6.0.1

Capacitor:

Capacitor CLI : 3.3.3 @capacitor/android : not installed @capacitor/core : 3.3.3 @capacitor/ios : not installed

Utility:

cordova-res : not installed globally native-run : 1.5.0

System:

NodeJS : v16.10.0 (C:\Program Files\nodejs\node.exe) npm : 8.0.0 OS : Windows 10

Additional Information

Reason for using menuController is that I need multiple menus on the same side and in order to do that I had to first enable a menu to be toggled:

const toggleMenu = async (menuId: string) => {
  await menuController.enable(true, menuId)
  await menuController.toggle(menuId)
}

Inspired by: https://forum.ionicframework.com/t/allow-multiple-menus/189934/4

If I don’t enable the menu, I can toggle only 1 of the menus assigned to “start” side. This is demonstrated by buttons under “Toggle menu directly” header in my demo application: https://github.com/nika1001/ionic6-menu-controller-issue

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:19 (10 by maintainers)

github_iconTop GitHub Comments

5reactions
sean-perkinscommented, Jan 5, 2022

Thanks for reporting this! While the behavior of only having one enabled menu at a time is a known limitation to how we currently approach multiple menus, the behavior for toggling the enabled state and displaying the menu does appear to have regressed from v5 to v6.

We’ll track this bug and share an update when we are able. Thanks!

2reactions
sean-perkinscommented, Mar 24, 2022

@mlegenhausen thanks for the work on this issue. I have confirmed:

  1. @ionic/core is being bundled because of the componentOnReady import.
  2. The import for menuController must come from @ionic/core/components.

I’ll open a PR to get this resolved and add you as a co-contributor for the assistance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I programmatically close the side menu in Ionic React?
bug : unable to control IonMenu programmatically using MenuController. opened 12:44PM - 29 Dec 21 UTC. nika1001. package: react type: bug.
Read more >
How close menu from ionic 5 - Stack Overflow
I put in the constructor "public menuCtrl: MenuController" and in ngOnInit: this.menuCtrl.close();. but nothing works. From debug I see menuCtrl ...
Read more >
How to dynamically show an ion-menu in Ionic 4 - Jordan Benge
We'll be using a service to handle passing our menu links to the side-menu component. This is so the menu links can be...
Read more >
Ionic 5 - 09 Ion Menu - YouTube
The Menu component is a navigation drawer that slides in from the side ... from the templates, or programmatically using the MenuController.
Read more >
Ionic 5 Side Drawer menu - YouTube
The Menu component is a navigation drawer that slides in from the side ... from the templates, or programmatically using the MenuController.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found