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', () => {
243
243
} ) ;
244
244
} ) ;
245
245
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 ( ( ) => {
247
247
fixture = TestBed . createComponent ( SimpleTabHeaderApp ) ;
248
248
249
249
const inkBar = fixture . componentInstance . tabHeader . _inkBar ;
@@ -253,9 +253,10 @@ describe('MatTabHeader', () => {
253
253
254
254
change . next ( ) ;
255
255
fixture . detectChanges ( ) ;
256
+ tick ( 20 ) ; // Angular turns rAF calls into 16.6ms timeouts in tests.
256
257
257
258
expect ( inkBar . alignToElement ) . toHaveBeenCalled ( ) ;
258
- } ) ;
259
+ } ) ) ;
259
260
260
261
it ( 'should re-align the ink bar when the window is resized' , fakeAsync ( ( ) => {
261
262
fixture = TestBed . createComponent ( SimpleTabHeaderApp ) ;
Original file line number Diff line number Diff line change 8
8
9
9
import { Direction , Directionality } from '@angular/cdk/bidi' ;
10
10
import { ENTER , LEFT_ARROW , RIGHT_ARROW , SPACE } from '@angular/cdk/keycodes' ;
11
- import { startWith } from 'rxjs/operators/startWith' ;
12
11
import {
13
12
AfterContentChecked ,
14
13
AfterContentInit ,
@@ -188,11 +187,15 @@ export class MatTabHeader extends _MatTabHeaderMixinBase
188
187
ngAfterContentInit ( ) {
189
188
const dirChange = this . _dir ? this . _dir . change : observableOf ( null ) ;
190
189
const resize = this . _viewportRuler . change ( 150 ) ;
191
-
192
- this . _realignInkBar = merge ( dirChange , resize ) . pipe ( startWith ( null ) ) . subscribe ( ( ) => {
190
+ const realign = ( ) => {
193
191
this . _updatePagination ( ) ;
194
192
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 ) ;
196
199
}
197
200
198
201
ngOnDestroy ( ) {
You can’t perform that action at this time.
0 commit comments