Skip to content

Commit 9d18c89

Browse files
authored
refactor(material/tabs): Remove use of zone onStable for aligning tab header (#28653)
1 parent 9509ad5 commit 9d18c89

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/material/tabs/paginated-tab-header.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import {
2424
numberAttribute,
2525
Output,
2626
ANIMATION_MODULE_TYPE,
27+
afterNextRender,
28+
inject,
29+
Injector,
2730
} from '@angular/core';
2831
import {Direction, Directionality} from '@angular/cdk/bidi';
2932
import {ViewportRuler} from '@angular/cdk/scrolling';
@@ -39,7 +42,7 @@ import {
3942
timer,
4043
fromEvent,
4144
} from 'rxjs';
42-
import {take, switchMap, startWith, skip, takeUntil, filter} from 'rxjs/operators';
45+
import {switchMap, startWith, skip, takeUntil, filter} from 'rxjs/operators';
4346
import {Platform, normalizePassiveListenerOptions} from '@angular/cdk/platform';
4447

4548
/** Config used to bind passive event listeners */
@@ -153,6 +156,8 @@ export abstract class MatPaginatedTabHeader
153156
/** Event emitted when a label is focused. */
154157
@Output() readonly indexFocused: EventEmitter<number> = new EventEmitter<number>();
155158

159+
private _injector = inject(Injector);
160+
156161
constructor(
157162
protected _elementRef: ElementRef<HTMLElement>,
158163
protected _changeDetectorRef: ChangeDetectorRef,
@@ -209,9 +214,9 @@ export abstract class MatPaginatedTabHeader
209214

210215
// Defer the first call in order to allow for slower browsers to lay out the elements.
211216
// This helps in cases where the user lands directly on a page with paginated tabs.
212-
// Note that we use `onStable` instead of `requestAnimationFrame`, because the latter
213-
// can hold up tests that are in a background tab.
214-
this._ngZone.onStable.pipe(take(1)).subscribe(realign);
217+
// TODO(mmalerba): Consider breaking this into multiple `afterNextRender` calls with explicit
218+
// phase.
219+
afterNextRender(realign, {injector: this._injector});
215220

216221
// On dir change or window resize, realign the ink bar and update the orientation of
217222
// the key manager if the direction has changed.

0 commit comments

Comments
 (0)