@@ -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,30 @@ 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 itemsTracked = new Set < MatPaginatedTabHeaderItem > ( ) ;
254
+ const itemContainerItemChanged = new Subject < void > ( ) ;
255
+
256
+ const observer = new ResizeObserver ( ( ) => {
257
+ itemContainerItemChanged . next ( ) ;
258
+ } ) ;
259
+
260
+ return merge ( this . _items . changes , itemContainerItemChanged ) . pipe (
261
+ startWith ( this . _items ) ,
262
+ map ( ( ) => {
263
+ for ( const item of this . _items . toArray ( ) ) {
264
+ if ( ! itemsTracked . has ( item ) ) {
265
+ observer . observe ( item . elementRef . nativeElement ) ;
266
+ }
267
+ }
268
+ this . _items . forEach ( item => itemsTracked . add ( item ) ) ;
269
+ } ) ,
270
+ ) ;
271
+ }
272
+
249
273
ngAfterContentChecked ( ) : void {
250
274
// If the number of tab labels have changed, check if scrolling should be enabled
251
275
if ( this . _tabLabelCount != this . _items . length ) {
0 commit comments