Skip to content
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

Resizing mat-sidenav covers hamburger menu, won't auto size to content within? #12

Open
kelliev opened this issue Jun 2, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@kelliev
Copy link

kelliev commented Jun 2, 2020

Hey thanks for this! I'm having a problem with the size of the . If I change the width, it covers the hamburger menu. 

It's also not automatically sizing to the text of the buttons, as stated. If I have a longer button name, it wraps instead of pushing out the width to accommodate. 
Screen Shot 2020-06-02

Spent quite a while viewing the source code but I can't find a way to change this? Please help, it's sooooooo close!

@Jordan-Hall Jordan-Hall added the bug Something isn't working label Jun 2, 2020
@jphillips03
Copy link

jphillips03 commented Sep 22, 2023

I know it's been a while since this was originally posted, but I came across this issue recently myself. I did find a workaround, and thought I might share what I did to fix it.

If you know the width of your sidenav content before it renders you can simply set the expandedWidth input provided by the directive. This defaults to 200px as noted in the readme.

If you don't know the width of your sidenav content before it renders (which was my case), just setting the expandedWidth is not enough at least the way I did it. I calculated the width of the content in the sidenav in the AfterViewInit of my component, and set the openAnimation input added by the directive to a custom function I added to my component. The function I added I just copied from the default config, but used the width I calculated in the AfterViewInit. Something like below.

Function added to component.ts:

// this.sidenavContentWidth is calculated in ngAfterViewInit
sidebarAnimationOpenGroup(
    animationDuration: string = '100ms', // same value used from default config
    maxWidth: string = this.sidenavContentWidth
): AnimationGroupMetadata {
    return group([
        query('@iconAnimation', animateChild(), { optional: true }),
        query('@labelAnimation', animateChild(), { optional: true }),
        animate(`${animationDuration} ease-in-out`, sidebarOpen(maxWidth))
    ]);
}

Code in component.html

<mat-sidenav rail-mode [opened]="opened" [expandedWidth]="sidenavContentWidth" [openAnimation]="sidebarAnimationOpenGroup()">
    <!-- content -->
</mat-sidenav>

NOTE: Just updating the expandedWidth value does not seem to change anything if you don't know the width beforehand and need to calculate it dynamically (probably because openAnimation is set in ngOnInit).

Hope this helps.

jphillips03 added a commit to ngx-material-dashboard/ngx-material-dashboard that referenced this issue Sep 24, 2023
Set openAnimation input property on sidenav with calculated
width of content inside sideanv. This fixes issue with rail
sidenav cutting off content that goes beyond expanded width. Related to issue and workaround noted below:

Jordan-Hall/angular-material-rail-drawer-plugin#12 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants