Skip to content

[Tabs] Ink bar does not update when container resizes #6130

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

Closed
rbleuse opened this issue Jul 28, 2017 · 17 comments · Fixed by #24885
Closed

[Tabs] Ink bar does not update when container resizes #6130

rbleuse opened this issue Jul 28, 2017 · 17 comments · Fixed by #24885
Assignees
Labels
area: material/tabs P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@rbleuse
Copy link

rbleuse commented Jul 28, 2017

Bug, feature request, or proposal:

Bug :
Add stretched tabs in a sidenav container with side mode.
When the sidenav is resized with dynamic content (ie sidenav labels are translated), the md-ink-bar is not resized
That happens too with md-tab-nav-bar and full width tabs

What is the expected behavior?

md-ink-bar should be resized

What is the current behavior?

tabs are well resized but not md-ink-bar

What are the steps to reproduce?

plunkr :
https://plnkr.co/edit/q80nul7KYS8sJ0e8vwwi?p=preview
stackblitz :
https://stackblitz.com/edit/angular-material2-issue-6efd2m?file=main.ts

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

ng 5.1.1
material 5.0.1
chrome 61

Is there anything else we should know?

@andrewseguin andrewseguin self-assigned this Jul 28, 2017
@finalxcode
Copy link

+1

@rbleuse
Copy link
Author

rbleuse commented Sep 28, 2017

Is there any news about this ? I updated the plunker to latest angular & material2, and still same issue.

BTW it seems now that the sidenav is overlapping tabs

@andrewseguin andrewseguin changed the title md-ink-bar is not resized when md-sidenav content change [Tabs] Ink bar does not update when container resizes Oct 19, 2017
@andrewseguin andrewseguin added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed mat-tabs labels Oct 19, 2017
@anton-dragon
Copy link

Is there any workaround for this issue?

@alexw10
Copy link

alexw10 commented Feb 25, 2018

Hope this gets looked at soon, tried a few things to resolve this but no luck.

@Marshal27
Copy link

The issue to me appears that the _realignInkBar is only triggered by the _viewportRuler which is controlled by a window resize event. I attempted playing around with MutationObserver but unfortunately that is not able to monitor the values in the _tabListContainer.nativeElement that we would need for that to work.

Without a way to actively monitor either the clientWidth or offsetWidth values and trigger either an event or some type of changeDetection when those values are modified... I was stuck with the following hacky solution that allowed me to realign the inkBar after my resizing event. Not pretty but got the job done in my scenario.

Hope this helps others looking for a workaround to this issue.

setTimeout(() => {
window.dispatchEvent(new Event('resize'));
}, 100)

@rbleuse
Copy link
Author

rbleuse commented Mar 2, 2018

I personally fixed this issue in my project (i'm using a sidenav) by calling the private method _alignInkBar :

@ViewChild('matTabs') matTabs: MatTabNav;

ngOnInit() {
    this.sidenavService.getSidenav().onOpen
    .pipe(takeUntil(this.ngUnsubscribe))
    .subscribe(() => {
      this.alignInkBar();
    });
    this.sidenavService.getSidenav().onClose
    .pipe(takeUntil(this.ngUnsubscribe))
    .subscribe(() => {
      this.alignInkBar();
    });
  }

  // FIXME delete when https://github.com/angular/material2/issues/6130 is fixed
  alignInkBar() {
    setTimeout(() => {
      this.matTabs._alignInkBar();
    }, 0);
  }

  ngOnDestroy() {
    this.ngUnsubscribe.next();
    this.ngUnsubscribe.complete();
  }

@Marshal27
Copy link

@spanja thank you for sharing, your workaround is much more elegant!

@dannye
Copy link

dannye commented Aug 20, 2018

@spanja Thanks for your workaround. It appears _alignInkBar() has been renamed to realignInkBar()

An issue I have is that the mat-tab-group is in a router-outlet which is inside the mat-sidenav-content
So the mat-sidenav that causes the buggy mat-ink-bar isn't accessible in the script for the component that contains the mat-tab-group

For now I'm doing something similar to @spanja except I'm using ngDoCheck() instead:

ngDoCheck() {
  this.matTabs.realignInkBar();
}

The major downside to this is that the mat-ink-bar doesn't get corrected until the mat-sidenav is finished opening/closing. This delay looks extra bad because I have two mat-tab-groups in that component and the second tab group works correctly because its mat-tab-header-pagination-controls-enabled is always present, and the mat-ink-bar is always correctly animated if pagination controls are enabled, regardless of the changing width of the container.

A minor downside to this is that the mat-tab-group which uses realignInkBar() flickers between having its pagination controls enabled and disabled very sporadically, even when there is enough room such that the pagination controls should not be enabled at all.

Is there any news on this bug?
Or any advice on improving the downsides to this workaround?

Thanks

EDIT:
The sporadic flipping between pagination controls being enabled/disabled only happens when the selected tab is the right-most tab. It also isn't really a downside to the workaround, but actually a bug caused by mat-stretch-tabs

@pmilic021
Copy link

There is same issue with pagination arrows, if the container (not the window itself) is resized, pagination arrows won't recalculate, so I used similar hack for the time being:

@ViewChild(MatTabGroup) matTabGroup: MatTabGroup;

private updatePagination() {
    setTimeout(() => {
      this.matTabGroup._tabHeader.updatePagination();
    }, 0);
  }

@JGSolutions
Copy link

@pmilic021 When do you call the method updatePagination()?

@pmilic021
Copy link

@JGSolutions I had some animation for enlarging a div to full-screen mode, so I ran it at the end of the animation:
<div class="content-container" [@fullWidth]="isFullScreen" (@fullWidth.done)="updatePagination()">

@phillipe-barbosa
Copy link

+1

@IgorKurkov
Copy link

IgorKurkov commented Nov 23, 2020

+1
wrote workaround here #3048 (comment).
the same problem.

@pcnate
Copy link

pcnate commented Jan 8, 2021

The ink bar should have left and width set as a percentage. To avoid issues when tabs overflow the visible space the width of the ink bar parent should match the total space for the tabs and it should be moved left right with overflow hidden when tabs change.

For example, when you have 4 tabs. The element.style set by the library should reflect the following:

.mat-ink-bar  {
  left: 50%;
  width: 25%;
}

This would yield an ink bar that resizes with no API hacks that shows under the 3rd tab. Having 2 tabs to the left would be calculated with left = tabIndex * ( 1 / numberOfTabs ) and width = 1 / numberOfTabs

ezgif com-gif-maker

Additional styling would be required to deal with tabs that overflow the visible space.

@bierzorutas
Copy link

Same problem here... still present after more than 3 years

@andrewseguin
Copy link
Contributor

This is probably unlikely to be fixed since it is not an issue in the experimental MDC tabs version

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: material/tabs P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet