You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Tabs] Ink bar does not update when container resizes #6130
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
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?
Reacted by Isaac Mann, Viswanatha Swamy P K, Jeff Breunig , anton-dragon, alexw10, Christina Huege, AndrewMilko, raphael22, Alex Bolshakov, Philip and 6 more
changed the title [-]md-ink-bar is not resized when md-sidenav content change[/-][+][Tabs] Ink bar does not update when container resizes[/+]on Oct 19, 2017
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.
@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
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:
@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()">
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
Additional styling would be required to deal with tabs that overflow the visible space.
Activity
finalxcode commentedon Aug 14, 2017
+1
rbleuse commentedon 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
[-]md-ink-bar is not resized when md-sidenav content change[/-][+][Tabs] Ink bar does not update when container resizes[/+]anton-dragon commentedon Dec 13, 2017
Is there any workaround for this issue?
alexw10 commentedon Feb 25, 2018
Hope this gets looked at soon, tried a few things to resolve this but no luck.
Marshal27 commentedon Mar 2, 2018
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 commentedon Mar 2, 2018
I personally fixed this issue in my project (i'm using a sidenav) by calling the private method _alignInkBar :
Marshal27 commentedon Mar 2, 2018
@spanja thank you for sharing, your workaround is much more elegant!
dannye commentedon Aug 20, 2018
@spanja Thanks for your workaround. It appears
_alignInkBar()has been renamed torealignInkBar()An issue I have is that the
mat-tab-groupis in arouter-outletwhich is inside themat-sidenav-contentSo the
mat-sidenavthat causes the buggymat-ink-barisn't accessible in the script for the component that contains themat-tab-groupFor now I'm doing something similar to @spanja except I'm using
ngDoCheck()instead:The major downside to this is that the
mat-ink-bardoesn't get corrected until themat-sidenavis finished opening/closing. This delay looks extra bad because I have twomat-tab-groupsin that component and the second tab group works correctly because itsmat-tab-header-pagination-controls-enabledis always present, and themat-ink-baris 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-groupwhich usesrealignInkBar()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-tabspmilic021 commentedon Jan 15, 2019
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:
JGSolutions commentedon Mar 30, 2020
@pmilic021 When do you call the method updatePagination()?
pmilic021 commentedon Mar 30, 2020
@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 commentedon Oct 2, 2020
+1
IgorKurkov commentedon Nov 23, 2020
+1
wrote workaround here #3048 (comment).
the same problem.
pcnate commentedon 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:
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 )andwidth = 1 / numberOfTabsAdditional styling would be required to deal with tabs that overflow the visible space.
bierzorutas commentedon Mar 27, 2021
Same problem here... still present after more than 3 years
andrewseguin commentedon Mar 29, 2021
This is probably unlikely to be fixed since it is not an issue in the experimental MDC tabs version
angular-automatic-lock-bot commentedon Jun 18, 2022
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.