-
Notifications
You must be signed in to change notification settings - Fork 13.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: toggle menu when ion-split-pane is visible #18692
Comments
I had the same problem and found a fix. Previously I was just using:
To fix it, I am now using:
|
Thanks for the issue! If you just want the I'm not sure what framework you're using, but in vanilla JS it would be:
and in Angular:
Documentation on menu button properties: https://ionicframework.com/docs/api/menu-button#properties If you're running into the problem where there is a space even though the menu button is hidden, please subscribe to this issue: #18666 Thanks! |
@joelmeaders @brandyscarney You both completely got me wrong. I said I should be able to collapse and expand the side menu whenever I want. (I'm talking about desktop browser only). It's possible only if the menu button shows up. This is my requirement. I have another choice and get rid of I want the side-menu to be fixed, not overlay or something. It's unbelievable this tiny feature is missing from this popular framework. |
I still got this issue even upgrade to dev version of 4.6.1 |
@IsaacHub Thanks, I can update your original issue, but it was not clear from your description. |
Solution: For anyone wanting a right side menu that is always hidden in a SplitPane, just put it outside the SplitPane in your app.html. Then just programmatically show/hide it using MenuController.open/close. This should be documented! @IsaacHub Did you ever find a fix for this? I have a right side menu that I want to optionally show/hide on desktop, same as you do with your left. @brandyscarney How this still not a documented feature is beyond me! Thanks. |
@daveshirman I posted a detailed way to accomplish what you want here: #15538 (comment) |
Thanks - I ended up (by chance) figuring out that you can just put the second menu outside the split pane and it works as I wanted, with the left menu collapsing as normal and the right one always hidden. See my edit. Don't know if that achieves anything different to your solution which I've read. Cheers! Note: I see yours is V4, mine is V3. |
Is there a solution yet to the original problem ? |
If the menu is inside of a split pane use the "when" property on it. Pass in a boolean value of false. If it's false the menu is hidden on desktop unless it's swiped open or toggled. An observable in a singleton service does the trick nicely. It also plays nice with the toggle buttons and they're visible as they should be when the menu is not showing.
You can also just pass in "false" right there in the HTML to quickly test it out. |
Here's my solution to this problem - works really well:
Then in your view use an
|
@corysmc I tried your code snippet, and it worked. |
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')
} |
Only you need to add Example: <ion-split-pane contentId="main-content" when="false">...</ion-split-pane> |
this method make a sidebar was autohide for first look trick of @cameronrr, it works like a charm 🎉 but like a hacky, but unfortunately Ionic doesn't provide this functionality. |
The current behavior is great. The only problem is that the menu button is not able to trigger the menu anymore when the split-pane shows the menu. The |
Isn't the actual solution to this to bind |
@vicatcu In short: No, because the menu button still not work in this case. (as I wrote). |
This is the best simple solution. |
@corysmc @cameronrr you guys are the best! |
toggle menu in web format with animation, under the 992 it works normally, since only in web format the behavior was very rough. Can be improve but it works.
There is one thing that I could not solve, when changing the resolution manually the menu disappears without animation, but the content has animation so it is not very noticeable. |
Is anyone able to post a complete index.html page with this split pane effect working? |
Esta funcionalidad, algún día estará disponible de forma nativa |
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.
The text was updated successfully, but these errors were encountered: