Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic toggle menu doesn't close side menu on android device

I have an Ionic 4 project and I'm using a side menu. There's a menu button that opens the menu, and in the menu is a list of menu-choices, when selected the menu-choice closes the side menu. This works in a browser, but not on a device. The menu will open, but not close.

My side menu is in my app.component.html

<ion-app>
  <ion-menu side="start" type="push" contentId="content1">
      <ion-header>
        <ion-toolbar color="primary">
          <ion-title>Menu</ion-title>
        </ion-toolbar>
      </ion-header>
      <ion-content class="light-grey">
        <ion-list>
          <ion-item (click)="toggleMenu()" [routerLink]="['/home']" routerLinkActive="active-link">Home</ion-item>
          <ion-item (click)="toggleMenu()" [routerLink]="['/dashboard']" routerLinkActive="active-link">Dashboard</ion-item>
        </ion-list>
      </ion-content>
    </ion-menu>
    <ion-router-outlet id="content1" main></ion-router-outlet>
</ion-app>

Here is a sample of the homepage

<ion-header>
    <ion-toolbar>
        <ion-buttons slot="start">
            <ion-menu-button autoHide="false" menuToggle></ion-menu-button>
          </ion-buttons>
        <ion-title>
         Opportunity Forms
        </ion-title>
    </ion-toolbar>
  </ion-header>

<ion-content>
  <ion-refresher slot="fixed"  (ionRefresh)="ionRefresh($event)" >
      <ion-refresher-content 
          pulling-icon="arrow-dropdown"
          pulling-text="Pull to refresh"
          refreshing-spinner="circles"
          refreshing-text="Refreshing...">
      </ion-refresher-content>
    </ion-refresher>
  <ion-card> 
      <ion-card-content>


      </ion-card-content>
    </ion-card>
</ion-content>

Here is a screenshot of the app

enter image description here

Works in Chrome Version 77.0.3865.90 Tested and menu does not close on Android 9

Any help is appreciated, hopefully I've provided enough information.

-- Edit (adding app.component.ts) --

import { Component } from '@angular/core';

import { Platform } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import {MenuController} from '@ionic/angular';
import { Router } from '@angular/router';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss']
})
export class AppComponent {
  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar,
    private menu: MenuController,
    private route: Router
  ) {
    this.initializeApp();
  }

  initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();
    });
  }
  toggleMenu() {
    this.menu.toggle(); //Add this method to your button click function
  }
}
like image 339
Austin Jones Avatar asked Oct 11 '19 14:10

Austin Jones


People also ask

How do I turn off side menu in Ionic?

You can add some additional attributes to the ion-side-menus element. The enable-menu-with-back-views can be set to false to disable side menu, when the back button is showed. This will also hide the menu-toggle button from the header.

How do you close the side menu in Ionic 5?

ion-menu-toggle The MenuToggle component can be used to toggle a menu open or closed. We'll place all navigation links inside the MenuToggle component. When a user taps on the link, the side menu will automatically be closed.

How do I use the ion menu toggle?

The MenuToggle component can be used to toggle a menu open or closed. By default, it's only visible when the selected menu is active. A menu is active when it can be opened/closed. If the menu is disabled or it's being presented as a split-pane, the menu is marked as non-active and ion-menu-toggle hides itself.

How do I open the side menu in Ionic?

Note: ion-menu-toggle is used to open and close the side menu, therefore when you click on a menu item, it will close the side menu automatically.


1 Answers

Please see this. It discusses the issue: https://github.com/ionic-team/ionic/issues/19354

They suggest updating @ionic/angular to 4.11.2. That did not work for everyone but another proposed solution that worked for someone is:

<ion-menu-toggle menu="first" autoHide="false">
like image 131
brent Avatar answered Sep 17 '22 21:09

brent