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. (#30214)

(cherry picked from commit af29a92)
  • Loading branch information
kseamon authored and Andrew Seguin committed Dec 20, 2024
1 parent 4a040cb commit f9f8df3
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 @@ -217,6 +217,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 @@ -396,12 +397,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 @@ -571,6 +566,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 f9f8df3

Please sign in to comment.