Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions src/material/tabs/paginated-tab-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,17 @@ import {
import {ViewportRuler} from '@angular/cdk/scrolling';
import {FocusKeyManager, FocusableOption} from '@angular/cdk/a11y';
import {ENTER, SPACE, hasModifierKey} from '@angular/cdk/keycodes';
import {merge, of as observableOf, Subject, timer, fromEvent} from 'rxjs';
import {take, takeUntil} from 'rxjs/operators';
import {
merge,
of as observableOf,
Subject,
EMPTY,
Observer,
Observable,
timer,
fromEvent,
} from 'rxjs';
import {take, switchMap, startWith, skip, takeUntil} from 'rxjs/operators';
import {Platform, normalizePassiveListenerOptions} from '@angular/cdk/platform';
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';

Expand Down Expand Up @@ -218,7 +227,7 @@ export abstract class MatPaginatedTabHeader

// On dir change or window resize, realign the ink bar and update the orientation of
// the key manager if the direction has changed.
merge(dirChange, resize, this._items.changes)
merge(dirChange, resize, this._items.changes, this._itemsResized())
.pipe(takeUntil(this._destroyed))
.subscribe(() => {
// We need to defer this to give the browser some time to recalculate
Expand Down Expand Up @@ -246,6 +255,38 @@ export abstract class MatPaginatedTabHeader
});
}

/** A method responsible for sending any change that could affect layout about
* the items in this tab bar.
*/
private _itemsResized(): Observable<void> {
if (typeof ResizeObserver !== 'function') {
return EMPTY;
}

return this._items.changes.pipe(
startWith(this._items),
switchMap(
(tabItems: QueryList<MatPaginatedTabHeaderItem>) =>
new Observable((observer: Observer<void>) =>
this._ngZone.runOutsideAngular(() => {
const resizeObserver = new ResizeObserver(() => {
observer.next();
});
tabItems.forEach(item => {
resizeObserver.observe(item.elementRef.nativeElement);
});
return () => {
resizeObserver.disconnect();
};
}),
),
),
// Skip the first emit since the resize observer emits when an item
// is observed for new items when the tab is already inserted
skip(1),
);
}

ngAfterContentChecked(): void {
// If the number of tab labels have changed, check if scrolling should be enabled
if (this._tabLabelCount != this._items.length) {
Expand Down