Skip to content

Commit

Permalink
main - af29a92 perf(material/tooltip): Tiny but measurable optimizati…
Browse files Browse the repository at this point in the history
…on to MatTooltip construction. Defer hooking up to directionality changes until overlay is created. (#30214)
  • Loading branch information
kseamon committed Dec 20, 2024
1 parent 5c81604 commit 8b8e8e6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
14 changes: 9 additions & 5 deletions fesm2022/tooltip.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class MatTooltip {
_currentPosition;
_cssClassPrefix = 'mat-mdc';
_ariaDescriptionPending;
_dirSubscribed = false;
/** Allows the user to define the position of the tooltip relative to the parent element */
get position() {
return this._position;
Expand Down Expand Up @@ -238,11 +239,6 @@ class MatTooltip {
this.tooltipClass = defaultOptions.tooltipClass;
}
}
this._dir.change.pipe(takeUntil(this._destroyed)).subscribe(() => {
if (this._overlayRef) {
this._updatePosition(this._overlayRef);
}
});
this._viewportMargin = MIN_VIEWPORT_TOOLTIP_THRESHOLD;
}
ngAfterViewInit() {
Expand Down Expand Up @@ -384,6 +380,14 @@ class MatTooltip {
if (this._defaultOptions?.disableTooltipInteractivity) {
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;
}
/** Detaches the currently-attached tooltip. */
Expand Down
2 changes: 1 addition & 1 deletion fesm2022/tooltip.mjs.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tooltip/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export declare class MatTooltip implements OnDestroy, AfterViewInit {
private _currentPosition;
private readonly _cssClassPrefix;
private _ariaDescriptionPending;
private _dirSubscribed;
/** Allows the user to define the position of the tooltip relative to the parent element */
get position(): TooltipPosition;
set position(value: TooltipPosition);
Expand Down

0 comments on commit 8b8e8e6

Please sign in to comment.