-
Notifications
You must be signed in to change notification settings - Fork 6.8k
refactor(tabs): provide method for re-aligning the ink bar #10343
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
refactor(tabs): provide method for re-aligning the ink bar #10343
Conversation
@@ -224,6 +226,13 @@ export class MatTabGroup extends _MatTabGroupMixinBase implements AfterContentIn | |||
this._tabLabelSubscription.unsubscribe(); | |||
} | |||
|
|||
/** Re-aligns the ink bar to the selected tab element. */ | |||
realignInkBar() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test in for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, although these tests that have to do with element dimensions/positioning tend to be very flaky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not able to make this work. I am subscribing to a change in the menu toggle (when the matsidenav is opening or closing), and then I realign the nav bar each time a toggle happens, but the aligning is still not correct :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I experimented using a timeout like this:
setTimeout(() => {
this.tabGroup.realignInkBar();
}, 300);
This will align the inkbar, but it has to wait for the first animation to finish (being pushed because the sidenav is expanding), and then animate back to the correct position. I will try to make a Stackblitz to illustrate what I mean. Maybe I am doing something fundamentally wrong to begin with.
Adds the `realignInkBar` method to the `MatTabGroup` which allows consumers to re-align the ink bar programmatically. This is useful for the cases where Material can't figure out that it needs to be re-aligned or doing so would be very inefficient. Fixes angular#10340.
5743677
to
6d234c0
Compare
@crisbeto how would i use this realignInkBar() method in a component? having some trouble setting up the references, and the main app module |
Add a view child on your component then call export class MyComponent {
@ViewChild(MatTabGroup) tabGroup: MatTabGroup
someMethod() {
this.tabGroup.realignInkBar();
}
} At least I think that is the intended behavior. I did not try it. |
Thank you @prestonvanloon Just as a side note for anyone who ends up having the same issue. If you're using a mat-tab-nav-bar, you do the following (it's pretty much the same thing as for the MatTabGroup):
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Adds the
realignInkBar
method to theMatTabGroup
which allows consumers to re-align the ink bar programmatically. This is useful for the cases where Material can't figure out that it needs to be re-aligned or doing so would be very inefficient.Fixes #10340.