mat-ink-bar location not update when container resizes

只谈情不闲聊 提交于 2021-01-25 03:53:04

问题


I using angular-material mat-tab-nav-bar

I have side menu on the right side of the screen, click on it change the width of the side menu, and the center screen width change according to the menu width.

the problem is that the mat-ink-bar right/left position not changed.

Any idea?


回答1:


You can force the ink bar to re-align by calling realignInkBar() on mat-tab-group,check out this example on StackBlitz

To read further on the bug check out this thread




回答2:


It is not the best solution ever, but as a workaround, it works.

In my case content loads, and causes a vertical scrollbar, it resizes the page a bit (but window.onresize doesn't catch this resize event, so can't catch it yet), and sets the wrong alignment to mat-ink. My workaround - listen for routing event, wait for content loading by setTimeout with 1sec delay and realign mat-ink.

@ViewChild('matTabsRef', { static: false }) matTabsRef: MatTabNav;

fixResizeInkBar() {
  setTimeout(() => {
      if (this.matTabsRef) {
        this.matTabsRef._alignInkBarToSelectedTab();
      }
    }, 1000);
}

private listenRoutes(): void {
    this.subs.add(
      this.router.events
        .pipe(
          filter((event) => event instanceof NavigationEnd),
          startWith(true)
        )
        .subscribe((event) => {
          this.fixResizeInkBar();
        })
  );
}


来源:https://stackoverflow.com/questions/59017741/mat-ink-bar-location-not-update-when-container-resizes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!