Skip to content

perf(material/tooltip): Tiny but measurable optimization to MatToolti… #30214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2024
Merged
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
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
Loading