Hi, I’m looking a way to set the max-width of the SplitPane
The auto-size function is great, but I would like to set the “max-width” the side panel can reach. Because in big screens (for desktop of course) it gets really wide.
Screen Example:
As a reference, the base css for the menu is max-width: 28% and min-width: 270px. It is set directly in all three platforms .scss files for the component.
I check in app.component.ts on the initializeApp () method which platform is running.
app.component.ts
initializeApp() {
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
this.statusBar.styleDefault();
this.splashScreen.hide();
if (this.platform.is('core')) {
this.renderer.setElementStyle(this.menu._elementRef.nativeElement, "max-width", "100px");
}
});
}
ion-menu {
// md
// https://ionicframework.com/docs/api/components/split-pane/SplitPane/
// Show the split-pane when the min-width is 768px (default break point)
max-width: 768px;
}
If it is started in a Desktop Browser, the menu will be smaller with 100px, if it is other platforms it will set the default value.
However, the side and main pane widths are set through flex: 1, which means they try to have the same width. This is countered by $split-pane-side-max-width variable, but then we no longer have 3 parameters (min, width and max) but only 2 (min and max, width being always bigger than max).
To restore the situation, we have to modify the panes flex-grow property to a more suitable proportion, e.g.:
.split-pane-visible >.split-pane-side {
flex-grow: 28;
}
.split-pane-visible >.split-pane-main {
flex-grow: 72;
}
/* This proportion keeps the same behaviour as default,
but through flex instead of relying on max-width */
Now the width of the side pane is still 28% of the screen, but we can use absolute units for the max, so that the side pane does not grow too big on big screens:
.split-pane-visible >.split-pane-side {
min-width: 200px; /* Default: 270px */
max-width: 304px; /* Same as when menu opens in mobile mode */
}