-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
fix(navbar): update ink bar when links change #4897
Conversation
@@ -37,10 +41,14 @@ export class MdTabNavBar implements AfterContentInit, OnDestroy { | |||
/** Combines listeners that will re-align the ink bar whenever they're invoked. */ | |||
private _realignInkBar: Subscription = null; | |||
|
|||
/** Subject that emits when the component has been destroyed. */ | |||
private _onDestroy = new Subject<void>(); |
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.
Instead of having an internal Subject
, why not save the subscription and unsubscribe on destroy instead? On a related note, I wonder whether the _tabLinks
wouldn't get completed automatically on destroy.
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.
Both work, playing with the idea of using this subject for our components' subscriptions. It's an idea Rob is considering making "a thing" that seems to play nice with observables and lets you avoid storing the subscription in another variable.
What do you think about this @jelbourn
Changed the strategy to tackle another issue - align ink bar when the inner HTML changes. Using mutation observers to know when the content is changed. Can use this for when links are added/removed/moved as well as when their content has changed (and perhaps their width). @jelbourn can you re-review? |
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.
LGTM, one minor comment
(add merge-ready when done)
expect(inkBar.alignToElement).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should re-align the ink bar when the tab labels change the width', done => { |
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.
Why does this test use the done
callback instead of fakeAsync
? I actually don't see why either is necessary
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.
Nothing seemed to be able to trigger the mutation observer (detect changes, flush microtasks, etc). Took a cue from observe-content.spec.ts which uses done => ()
as well.
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. |
Fixes #4737, #4738
When the list of tab links change, the ink bar should adjust to make sure it's positioned under the right element. E.g. tabs are added/removed/moved/content changed