Different ion-split-pane depending on screen size like modern sidemenus with dock state

Hi, I’m using the default ion-split-pane from the starter template.
It’s perfect for small and large screens, but not really good middle screens. Can I show a smaller/thinner ion-split-pane on middle screens? Something like when="(min-width: 300px) and (max-width: 500px)"
So it would be:
small: burger menu
middle: thin sidemenu only icon
large: full sidemenu icon and text

something like this:
capture_001_08042022_230511

Hi

There is a css custom property defining the width. I’d try to use a media query to change this and also to disable the labels in the menu

But haven’t tried it yet

Would be nice to know how though

I got you @basti
ive been wondering about this for a while as well

  • in addition to what @Tommertom mentioned with split-pane, ionic has a CSS utility class ion-hide-{breakpoint}-{direction}
    CSS Utilities - Element Display

  • Use this on the icon and label child elements of the menu links. I had to create 3 instances since it seems you cannot apply an up AND down utility class to 1 element. to implement the custom width breakpoints, either alter them in the global styles, or use a media query on the specific ion-icons and labels, and adjust the split-pane/menu css

  • Finally, add the previously referenced css for the ion-spilt-pane and ion-menu.

You could potentially look at creating a custom component that contains this template/css but aside from that, let me know if this yields the correct results for you or if you find something simpler

app.component.html – modify the ion-item as follows:

<!-- Icon and label for hamburger menu at xs breakpoint -->
<ion-icon class="ion-hide-sm-up" slot="start" [ios]="p.icon + '-outline'" [md]="p.icon + '-sharp'"></ion-icon>
<ion-label class="ion-hide-sm-up">{{ p.title }}</ion-label>

<!-- icon only for sm 'modern' style -->
<ion-icon class="ion-hide-sm-down ion-hide-md-up" [ios]="p.icon + '-outline'" [md]="p.icon + '-sharp'"></ion-icon>

<!-- icon and label again for full size menu -->
<ion-icon class="ion-hide-md-down" slot="start" [ios]="p.icon + '-outline'" [md]="p.icon + '-sharp'"></ion-icon>
<ion-label class="ion-hide-md-down">{{ p.title }}</ion-label>

and then in app.component.css add:

ion-split-pane {
    --side-width: 270px !important;
    --side-max-width: 270px !important;
    ion-menu {
        --width: 270px !important;
        --max-width: 270px !important;
    }
}

@media screen and (max-width: 768px) {
    ion-split-pane {
        --side-width: 68px !important;
        --side-max-width: 68px !important;
        --side-min-width: 68px !important;
        ion-menu {
            --width: 68px !important;
            --max-width: 68px !important;
            --min-width: 68px !important;
        }
    }
}

@media screen and (min-width: 768px) {
    ion-split-pane {
        --side-width: 270px !important;
        --side-max-width: 270px !important;
        ion-menu {
            --width: 270px !important;
            --max-width: 270px !important;
        }
    }
}
2 Likes

Thanks for your answer! It sounds very great and I copied it, but I think the behaviour ist not like you mentioned it:

Unbenannt

Or is it the way you thought?

Shoot looks like I missed the minimum breakpoint being the full width, just gotta adjust the css I think

Ok, thanks again, I think I have it so far :wink: :

I had to add when="(min-width: 576px)" to the splitpane:
<ion-split-pane when="(min-width: 576px)" contentId="main-content">

and and (min-width: 576px) in the css:

ion-split-pane {
  --side-width: 270px !important;
  --side-max-width: 270px !important;
  ion-menu {
    --width: 270px !important;
    --max-width: 270px !important;
  }
}

@media screen and (min-width: 576px) and (max-width: 992px) {
  ion-split-pane {
    --side-width: 68px !important;
    --side-max-width: 68px !important;
    --side-min-width: 68px !important;
    ion-menu {
      --width: 68px !important;
      --max-width: 68px !important;
      --min-width: 68px !important;
    }
  }
}

@media screen and (min-width: 992px) {
  ion-split-pane {
    --side-width: 270px !important;
    --side-max-width: 270px !important;
    ion-menu {
      --width: 270px !important;
      --max-width: 270px !important;
    }
  }
}

Last question:
In the icon only version, the label is just missing. This has the consequence that the icons are on the same place (left) and on the right remains empty space. Any change to center them? With margin and padding I’d no chance.