Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/lib/tabs/tab-header.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ describe('MatTabHeader', () => {
});
});

it('should re-align the ink bar when the direction changes', () => {
it('should re-align the ink bar when the direction changes', fakeAsync(() => {
fixture = TestBed.createComponent(SimpleTabHeaderApp);

const inkBar = fixture.componentInstance.tabHeader._inkBar;
Expand All @@ -253,9 +253,10 @@ describe('MatTabHeader', () => {

change.next();
fixture.detectChanges();
tick(20); // Angular turns rAF calls into 16.6ms timeouts in tests.

expect(inkBar.alignToElement).toHaveBeenCalled();
});
}));

it('should re-align the ink bar when the window is resized', fakeAsync(() => {
fixture = TestBed.createComponent(SimpleTabHeaderApp);
Expand Down
11 changes: 7 additions & 4 deletions src/lib/tabs/tab-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import {Direction, Directionality} from '@angular/cdk/bidi';
import {ENTER, LEFT_ARROW, RIGHT_ARROW, SPACE} from '@angular/cdk/keycodes';
import {startWith} from 'rxjs/operators/startWith';
import {
AfterContentChecked,
AfterContentInit,
Expand Down Expand Up @@ -188,11 +187,15 @@ export class MatTabHeader extends _MatTabHeaderMixinBase
ngAfterContentInit() {
const dirChange = this._dir ? this._dir.change : observableOf(null);
const resize = this._viewportRuler.change(150);

this._realignInkBar = merge(dirChange, resize).pipe(startWith(null)).subscribe(() => {
const realign = () => {
this._updatePagination();
this._alignInkBarToSelectedTab();
});
};

// Defer the first call in order to allow for slower browsers to lay out the elements.
// This helps in cases where the user lands directly on a page with paginated tabs.
typeof requestAnimationFrame !== 'undefined' ? requestAnimationFrame(realign) : realign();
this._realignInkBar = merge(dirChange, resize).subscribe(realign);
}

ngOnDestroy() {
Expand Down