@@ -32,7 +32,7 @@ import {ViewportRuler} from '@angular/cdk/scrolling';
3232import { FocusKeyManager , FocusableOption } from '@angular/cdk/a11y' ;
3333import { ENTER , SPACE , hasModifierKey } from '@angular/cdk/keycodes' ;
3434import { 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' ;
3636import { Platform , normalizePassiveListenerOptions } from '@angular/cdk/platform' ;
3737import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations' ;
3838
@@ -218,7 +218,7 @@ export abstract class MatPaginatedTabHeader
218218
219219 // On dir change or window resize, realign the ink bar and update the orientation of
220220 // the key manager if the direction has changed.
221- merge ( dirChange , resize , this . _items . changes )
221+ merge ( dirChange , resize , this . _getItemChanges ( ) )
222222 . pipe ( takeUntil ( this . _destroyed ) )
223223 . subscribe ( ( ) => {
224224 // We need to defer this to give the browser some time to recalculate
@@ -246,6 +246,35 @@ export abstract class MatPaginatedTabHeader
246246 } ) ;
247247 }
248248
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 . run ( ( ) => {
271+ observer . observe ( item . elementRef . nativeElement ) ;
272+ } ) ;
273+ }
274+ } ) ,
275+ ) ;
276+ }
277+
249278 ngAfterContentChecked ( ) : void {
250279 // If the number of tab labels have changed, check if scrolling should be enabled
251280 if ( this . _tabLabelCount != this . _items . length ) {
0 commit comments