Skip to content

[MdSidenav] - Sidenav Resizing Regression #6743

Closed

Description

@dereekb

Bug, feature request, or proposal:

Bug/Regression from 2.0.0-beta.8.

Also a feature request for an API to allow triggering recalculations for the MdSidenavContainer/MdDrawerContainer, or being able to update _styles manually and having the view update..

What is the expected behavior?

In the previous release 2.0.0-beta.8 the sidenav resized when the window was resized.

I have a responsive sidenav that uses Angular flex-layout for showing/hiding responsive content in the sidenav when the view changes from md to lg and vice-versa.

What is the current behavior?

In 2.0.0-beta.10 this is no longer the case. The changes made in #6189 made the sidenav update only when the sidenav is opening/closing.

Since flex-layout's changes occur without having to call open() or close() on the sidenav, the width recalculation doesn't occur.

example

What are the steps to reproduce?

Put dynamic/responsive content within a sidenav that is configured with "side".

What is the use-case or motivation for changing an existing behavior?

Being able to dynamically call a refresh of the MdSidenav/MdDrawer or MdSidenavContainer/MdDrawerContainer.

Even better would be an accessor to allow manually setting the margin of the sidenav to allow for pre-computing the _style variable and updating it when needed.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular 4.3.5
Angular Material 2.0.0-beta.10

Is there anything else we should know?

This is similar to #6583.

For right now I am using the following hack in my navigation directive to workaround whenever the ObservableMedia from angular flex-layout changes:

// Timeout required for flex-layout directives to update the child views/the width.
setTimeout(() => {
            (this._container as any)._updateStyles();
            (this._container as any)._changeDetectorRef.markForCheck();
}, 0);

Activity

  1. djfishe commented on Sep 4, 2017

    @djfishe

    +1. Same issue I have after upgrading to 2.0.0-beta.10

  2. sbeaufort commented on Sep 6, 2017

    @sbeaufort

    Same issue after upgrading from 2.0.0-beta.8 to 2.0.0-beta.10

    My workarround :

    app.component.html

    <md-sidenav class="main-sidenav" #sidenav mode="side" opened="false">

    app.component.ts

    export class AppComponent implements  AfterViewInit {
    
      @ViewChild('sidenav') 
      private sidenav: MdSidenav;
    
      ngAfterViewInit(): void {
        setTimeout(() => {
          this.sidenav.open();
        }, 250);
      }
    }
    
    
  3. bleuscyther commented on Sep 6, 2017

    @bleuscyther

    that is exactly what i did @sbeaufort. It creates a small animation at the first page load but its ok

  4. AppField commented on Sep 10, 2017

    @AppField

    I have the exact same issue.

  5. ghwyf commented on Sep 11, 2017

    @ghwyf

    Here is my solution:
    HTML

    <md-sidenav-container #container>
        <md-sidenav  mode="side" opened="{{showMenu}}" class="shadow"></md-sidenav>
        <div class="my-content"></div>
    </md-sidenav-container>
    

    TS

    export class MyComponent implements OnInit, AfterViewInit {
        @ViewChild('container') private _container;
        public showMenu: boolean = false;
        ...
        ngAfterViewInit() {
          setTimeout(()=>{
            this.showMenu = true;
          },0);
          this._container._ngZone.onMicrotaskEmpty.subscribe(() => {
            this._container._updateStyles();
            this._container._changeDetectorRef.markForCheck();
          })
        };
        ...
    }
    
  6. AppField commented on Sep 11, 2017

    @AppField

    @ghwyf Thank you very much! This workaround also worked for me.

  7. benfontan commented on Sep 20, 2017

    @benfontan

    Same issue for me upgrading to 2.0.0-beta.10.
    I used @ghwyf fix which works perfectly, thank you.

  8. josephperrott commented on Sep 27, 2017

    @josephperrott
    Member

    Closing as duplicate of #1130

  9. upstreamosGH commented on Sep 28, 2017

    @upstreamosGH

    Join the responses of @angularexample in #1130 and @ghwyf here, works for me.
    ngAfterViewInit seems too heavy for my application so I replace it with a specific call only when Subscription happens.

  10. adrm commented on Sep 28, 2017

    @adrm

    @josephperrott I think the issues are about different things. The one you referenced is about opening and closing the sidenav automatically when viewport width changes. This one is about being able to resize the sidenav width while keeping it open.

    Before the last update this worked with no problem. Right now, the main content is not being resized when the sidebar width is resized. Some people have shared workarounds for this, but I think it would be nice if Angular Material would support this use case which is quite popular in places like firebase.

    Opened Closed
    image image
  11. josephperrott commented on Sep 28, 2017

    @josephperrott
    Member

    Reopening, sorry I misunderstood a bit there.

  12. 34 remaining items

  13. crisbeto commented on Dec 5, 2017

    @crisbeto
    Member

    @axtho what these changes do is allow you to opt in to having the drawer container resize once per change detection cycle, rather than on open/close.

  14. axtho commented on Dec 5, 2017

    @axtho

    @crisbeto so it is correct to assume that I would need to trigger change detection after running an animation when the component is on OnPush?

  15. crisbeto commented on Dec 5, 2017

    @crisbeto
    Member

    You might not have to since the sidenav will check inside ngDoCheck which keeps firing not matter the change detection strategy.

  16. gerardcarbo commented on Oct 1, 2018

    @gerardcarbo

    Still happening in 6.4.7:

    image

     "dependencies": {
        "@angular/animations": "6.1.8",
        "@angular/cdk": "^6.4.7",
        "@angular/common": "6.1.8",
        "@angular/compiler": "^6.1.8",
        "@angular/core": "6.1.8",
        "@angular/flex-layout": "^6.0.0-beta.18",
        "@angular/forms": "^6.1.8",
        "@angular/http": "6.1.8",
        "@angular/material": "^6.4.7",
        "@angular/platform-browser": "6.1.8",
        "@angular/platform-browser-dynamic": "6.1.8",
        "@angular/router": "6.1.8",
        "@angular/service-worker": "6.1.8",
        "@auth0/angular-jwt": "^2.0.0",
        "@ngx-formly/core": "^4.7.2",
        "@ngx-formly/material": "^4.7.2",
        "@ngx-translate/core": "^10.0.2",
        "@ngx-translate/http-loader": "^3.0.1",
        "core-js": "^2.5.2",
        "hammerjs": "^2.0.8",
        "material-design-icons-iconfont": "^3.0.3",
        "moment": "^2.22.1",
        "rxjs": "^6.3.2",
        "url": "^0.11.0",
        "util": "^0.11.0",
        "zone.js": "^0.8.26"
      },
      "devDependencies": {
        "@angular-devkit/build-angular": "^0.8.3",
        "@angular/cli": "^6.2.3",
        "@angular/compiler-cli": "^6.1.8",
        "@angular/language-service": "6.1.8",
        "@biesbjerg/ngx-translate-extract": "^2.3.1",
        "@ngx-rocket/scripts": "^2.1.0",
        "@types/jasmine": "^2.5.52",
        "@types/jasminewd2": "^2.0.2",
        "@types/lodash": "^4.14.103",
        "@types/node": "^8.9.4",
        "codelyzer": "^4.1.0",
        "htmlhint": "^0.10.1",
        "https-proxy-agent": "^2.0.0",
        "jasmine-core": "~2.99.1",
        "jasmine-spec-reporter": "^4.2.1",
        "karma": "^3.0.0",
        "karma-chrome-launcher": "^2.2.0",
        "karma-cli": "~1.0.1",
        "karma-coverage-istanbul-reporter": "^1.2.1",
        "karma-jasmine": "^1.1.0",
        "karma-jasmine-html-reporter": "^0.2.2",
        "karma-junit-reporter": "^1.2.0",
        "protractor": "^5.4.0",
        "stylelint": "~9.1.1",
        "stylelint-config-recommended-scss": "~3.1.0",
        "stylelint-config-standard": "~18.2.0",
        "stylelint-scss": "~2.5.0",
        "ts-node": "~5.0.0",
        "tslint": "~5.9.1",
        "typescript": "^2.9.2"
      }
    
  17. ojpbay commented on Oct 11, 2018

    @ojpbay

    Yep still an issue in 6.4.7
    "@angular/material": "^6.4.7"

  18. kflo commented on Oct 19, 2018

    @kflo

    Come on, wheres the fix...?

  19. aribrick commented on Oct 19, 2018

    @aribrick

    Same. This is still an issue in 6.4.7

  20. brookesouza commented on Oct 19, 2018

    @brookesouza

    This solution is still a bit of a hack, but it's less of a hack than setTimeout...

    @ViewChild('sidenavContainer') private sidenavContainer: MatSidenavContainer;
    
    this.sidenavContainer._contentMarginChanges
        .pipe(
            debounceTime(250),
            tap(() => this.sidenavContainer._contentMargins.left = this.sidenav._width),
        )
        .subscribe();
    
  21. bobbydowling commented on Nov 3, 2018

    @bobbydowling

    this.sidenavContainer.autosize = true;

    worked for me... after mucking with it for an hour. :(

  22. rb-mwindh commented on Nov 5, 2018

    @rb-mwindh

    I observed the same issue in 6.4.7, but only in certain cases:

    • when running the app in dev mode, there were no issues
    • when running the app in prod mode, the mat-sidenav-content was overlapped by the mat-sidenav
    • when disabling the buildOptimizer the issues disappeared
      When debugging the sourcecode of MatSidenavContainer, I recognized the code being executed to look like the source code of the 5.2.x branch
      (line 713): this._ngZone.run(() => this._contentMargins.next({left, right}));
      instead of
      (line 717): this._ngZone.run(() => this._contentMarginChanges.next(this._contentMargins));

    Finally I identified the buildOptimizer cache as the culprit. After deleting <project>/node_modules/@angular-devkit/build-optimizer/src/.cache everything worked like a charm.

  23. FirstVertex commented on Feb 6, 2019

    @FirstVertex

    @dereekb this issue should not be closed.
    Still exists in the year 2019.
    @bobbydowling solution is the only thing worked for me. And I mucked with it for like 3 hours.

  24. MeghnathDas commented on May 15, 2019

    @MeghnathDas

    this.sidenavContainer.autosize = true;

    worked for me... after mucking with it for an hour. :(

    Where did you put autoSize = true ?
    I have tried to put in OnInit() and AfterViewInit() but it didn't worked.

  25. FirstVertex commented on May 15, 2019

    @FirstVertex

    @MeghnathDas here is documentation of autosize flag. It is option of mat-drawer-container
    https://material.angular.io/components/sidenav/api#MatDrawerContainer
    HTH

  26. angular-automatic-lock-bot commented on Sep 10, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  27. locked and limited conversation to collaborators on Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions