Skip to content

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

Merged
merged 1 commit into from
Apr 12, 2018

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Mar 9, 2018

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 #10340.

@crisbeto crisbeto requested a review from andrewseguin as a code owner March 9, 2018 12:02
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Mar 9, 2018
@jelbourn jelbourn requested a review from josephperrott March 9, 2018 15:51
@@ -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() {
Copy link
Member

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?

Copy link
Member Author

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.

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 :/

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.
@crisbeto crisbeto force-pushed the 10340/tabs-realign-ink-bar branch from 5743677 to 6d234c0 Compare April 3, 2018 16:47
@crisbeto crisbeto added pr: lgtm action: merge The PR is ready for merge by the caretaker target: minor This PR is targeted for the next minor release and removed pr: needs review labels Apr 3, 2018
@tinayuangao tinayuangao merged commit 923c733 into angular:master Apr 12, 2018
@koverda
Copy link

koverda commented May 4, 2018

@crisbeto how would i use this realignInkBar() method in a component? having some trouble setting up the references, and the main app module

@prestonvanloon
Copy link

prestonvanloon commented Jun 11, 2018

@koverda

Add a view child on your component then call realignInkBar.

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.

@koverda
Copy link

koverda commented Jun 29, 2018

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):

export class MyComponent {
  @ViewChild(MatTabNav) tabGroup: MatTabNav

   someMethod() {
     this.tabGroup._alignInkBar();
   }
}

@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 Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tabs inkbar position not recalculated on programmatical width change
9 participants