Skip to content

Commit

Permalink
perf(material/tooltip): Tiny but measurable optimization to MatToolti…
Browse files Browse the repository at this point in the history
…p construction. Defer hooking up to directionality changes until overlay is created.
  • Loading branch information
kseamon committed Dec 18, 2024
1 parent 5347d8c commit bcedffe
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/material/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
private _currentPosition: TooltipPosition;
private readonly _cssClassPrefix: string = 'mat-mdc';
private _ariaDescriptionPending: boolean;
private _dirSubscribed = false;

/** Allows the user to define the position of the tooltip relative to the parent element */
@Input('matTooltipPosition')
Expand Down Expand Up @@ -395,12 +396,6 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
}
}

this._dir.change.pipe(takeUntil(this._destroyed)).subscribe(() => {
if (this._overlayRef) {
this._updatePosition(this._overlayRef);
}
});

this._viewportMargin = MIN_VIEWPORT_TOOLTIP_THRESHOLD;
}

Expand Down Expand Up @@ -567,6 +562,15 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
this._overlayRef.addPanelClass(`${this._cssClassPrefix}-tooltip-panel-non-interactive`);
}

if (!this._dirSubscribed) {
this._dirSubscribed = true;
this._dir.change.pipe(takeUntil(this._destroyed)).subscribe(() => {
if (this._overlayRef) {
this._updatePosition(this._overlayRef);
}
});
}

return this._overlayRef;
}

Expand Down

0 comments on commit bcedffe

Please sign in to comment.