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.

feat: toggle menu when ion-split-pane is visible

See original GitHub issue

I’m using <ion-split-pane> and I need the menu toggle button on all screen sizes, how can I achieve this?

In desktop toggle menu doesn’t appear, and <ion-menu-button></ion-menu-button> exists in all pages’ toolbar.

Toggle menu only show up in the mobile view, but I want this in desktop view also.

ionicsplitpane

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:21 (4 by maintainers)

github_iconTop GitHub Comments

15reactions
cameronrrcommented, Jul 29, 2020

Add a click handler on the standard ion-menu-toggle button. Make sure ‘auto-hide=“false”’ is set on the toggle so the button is always visible even in split pane mode.

In the event handler, check the ion-split-pane ‘when’ attribute against the ionic media query breakpoints (or directly if not using a breakpoint alias). If the screen width is large enough to usually show the split panel, toggle the visibility to toggle the menu display.

The default click handler to animate menu in single pane view still works as per normal.

<ion-buttons slot="start">
    <ion-menu-toggle auto-hide="false" menu="main-menu">
        <ion-button @click="toggleMenu">
            <ion-icon slot="icon-only" name="menu"></ion-icon>
        </ion-button>
    </ion-menu-toggle>
</ion-buttons>
import { SIZE_TO_MEDIA } from '@ionic/core/dist/collection/utils/media'

toggleMenu: () => {
    const splitPane = document.querySelector('ion-split-pane')
    if (window.matchMedia(SIZE_TO_MEDIA[splitPane.when] || splitPane.when).matches)
        splitPane.classList.toggle('split-pane-visible')
}
6reactions
siutaucommented, Dec 28, 2020

Only you need to add when="false" in ion-menu-toggle

Example:

<ion-split-pane contentId="main-content" when="false">...</ion-split-pane>
Read more comments on GitHub >

github_iconTop Results From Across the Web

ion-menu-toggle - Ionic Framework
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....
Read more >
Ionic 3 split pane menu toggle not displayed - Stack Overflow
This way when the pane is shown it'll not show the menu button, but when in smaller screens and the pane is hidden,...
Read more >
July 6, 2020, 4:08 am - Ionic Framework - Ionic Forum
Upcoming feat: upload through http return progress and response ... <ion-menu-toggle auto-hide="false"> <ion-item *ngFor="let nav of navi" button ...
Read more >
How to Create an Effective Ionic Menu With and Without a ...
Use an ngFor directive inside of an ion-menu-toggle component. ... attribute to the ion-split-pane to indicate when you want it visible.
Read more >
Logo Design, Web Design and E-commerce ... - The Branding Store
Remember that the function acts like a toggle, removing the comic if it was ... <IonSplitPane contentId="main"> <Menu appPages={appPages} /> <IonPage ...
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