File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed
Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -243,7 +243,7 @@ describe('MatTabHeader', () => {
243243 } ) ;
244244 } ) ;
245245
246- it ( 'should re-align the ink bar when the direction changes' , ( ) => {
246+ it ( 'should re-align the ink bar when the direction changes' , fakeAsync ( ( ) => {
247247 fixture = TestBed . createComponent ( SimpleTabHeaderApp ) ;
248248
249249 const inkBar = fixture . componentInstance . tabHeader . _inkBar ;
@@ -253,9 +253,10 @@ describe('MatTabHeader', () => {
253253
254254 change . next ( ) ;
255255 fixture . detectChanges ( ) ;
256+ tick ( 20 ) ; // Angular turns rAF calls into 16.6ms timeouts in tests.
256257
257258 expect ( inkBar . alignToElement ) . toHaveBeenCalled ( ) ;
258- } ) ;
259+ } ) ) ;
259260
260261 it ( 'should re-align the ink bar when the window is resized' , fakeAsync ( ( ) => {
261262 fixture = TestBed . createComponent ( SimpleTabHeaderApp ) ;
Original file line number Diff line number Diff line change 88
99import { Direction , Directionality } from '@angular/cdk/bidi' ;
1010import { ENTER , LEFT_ARROW , RIGHT_ARROW , SPACE } from '@angular/cdk/keycodes' ;
11- import { startWith } from 'rxjs/operators/startWith' ;
1211import {
1312 AfterContentChecked ,
1413 AfterContentInit ,
@@ -188,11 +187,15 @@ export class MatTabHeader extends _MatTabHeaderMixinBase
188187 ngAfterContentInit ( ) {
189188 const dirChange = this . _dir ? this . _dir . change : observableOf ( null ) ;
190189 const resize = this . _viewportRuler . change ( 150 ) ;
191-
192- this . _realignInkBar = merge ( dirChange , resize ) . pipe ( startWith ( null ) ) . subscribe ( ( ) => {
190+ const realign = ( ) => {
193191 this . _updatePagination ( ) ;
194192 this . _alignInkBarToSelectedTab ( ) ;
195- } ) ;
193+ } ;
194+
195+ // Defer the first call in order to allow for slower browsers to lay out the elements.
196+ // This helps in cases where the user lands directly on a page with paginated tabs.
197+ typeof requestAnimationFrame !== 'undefined' ? requestAnimationFrame ( realign ) : realign ( ) ;
198+ this . _realignInkBar = merge ( dirChange , resize ) . subscribe ( realign ) ;
196199 }
197200
198201 ngOnDestroy ( ) {
You can’t perform that action at this time.
0 commit comments