@@ -32,7 +32,7 @@ import {ViewportRuler} from '@angular/cdk/scrolling';
32
32
import { FocusKeyManager , FocusableOption } from '@angular/cdk/a11y' ;
33
33
import { ENTER , SPACE , hasModifierKey } from '@angular/cdk/keycodes' ;
34
34
import { merge , of as observableOf , Subject , timer , fromEvent } from 'rxjs' ;
35
- import { take , takeUntil } from 'rxjs/operators' ;
35
+ import { take , map , startWith , takeUntil } from 'rxjs/operators' ;
36
36
import { Platform , normalizePassiveListenerOptions } from '@angular/cdk/platform' ;
37
37
import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations' ;
38
38
@@ -218,7 +218,7 @@ export abstract class MatPaginatedTabHeader
218
218
219
219
// On dir change or window resize, realign the ink bar and update the orientation of
220
220
// the key manager if the direction has changed.
221
- merge ( dirChange , resize , this . _items . changes )
221
+ merge ( dirChange , resize , this . _getItemChanges ( ) )
222
222
. pipe ( takeUntil ( this . _destroyed ) )
223
223
. subscribe ( ( ) => {
224
224
// We need to defer this to give the browser some time to recalculate
@@ -246,6 +246,35 @@ export abstract class MatPaginatedTabHeader
246
246
} ) ;
247
247
}
248
248
249
+ /** A method responsible for sending any change that could affect layout about
250
+ * items to subscribers.
251
+ */
252
+ _getItemChanges ( ) {
253
+ const itemContainerItemChanged = new Subject < void > ( ) ;
254
+
255
+ // Check to see if ResizeObserver is supported and if not, stub the function
256
+ // out so that it does nothing if not supported
257
+ const observer =
258
+ typeof ResizeObserver === 'function'
259
+ ? new ResizeObserver ( ( ) => {
260
+ itemContainerItemChanged . next ( ) ;
261
+ } )
262
+ : {
263
+ observe : ( ) => { } ,
264
+ } ;
265
+
266
+ return merge ( this . _items . changes , itemContainerItemChanged ) . pipe (
267
+ startWith ( this . _items ) ,
268
+ map ( ( ) => {
269
+ for ( const item of this . _items . toArray ( ) ) {
270
+ this . _ngZone . runOutsideAngular ( ( ) => {
271
+ observer . observe ( item . elementRef . nativeElement ) ;
272
+ } ) ;
273
+ }
274
+ } ) ,
275
+ ) ;
276
+ }
277
+
249
278
ngAfterContentChecked ( ) : void {
250
279
// If the number of tab labels have changed, check if scrolling should be enabled
251
280
if ( this . _tabLabelCount != this . _items . length ) {
0 commit comments