Skip to content

Commit

Permalink
refactor(material/tabs): Remove use of zone onStable for aligning tab…
Browse files Browse the repository at this point in the history
… header (#28653)
  • Loading branch information
mmalerba authored Mar 12, 2024
1 parent 9509ad5 commit 9d18c89
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/material/tabs/paginated-tab-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import {
numberAttribute,
Output,
ANIMATION_MODULE_TYPE,
afterNextRender,
inject,
Injector,
} from '@angular/core';
import {Direction, Directionality} from '@angular/cdk/bidi';
import {ViewportRuler} from '@angular/cdk/scrolling';
Expand All @@ -39,7 +42,7 @@ import {
timer,
fromEvent,
} from 'rxjs';
import {take, switchMap, startWith, skip, takeUntil, filter} from 'rxjs/operators';
import {switchMap, startWith, skip, takeUntil, filter} from 'rxjs/operators';
import {Platform, normalizePassiveListenerOptions} from '@angular/cdk/platform';

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

private _injector = inject(Injector);

constructor(
protected _elementRef: ElementRef<HTMLElement>,
protected _changeDetectorRef: ChangeDetectorRef,
Expand Down Expand Up @@ -209,9 +214,9 @@ export abstract class MatPaginatedTabHeader

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

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

0 comments on commit 9d18c89

Please sign in to comment.