Skip to content

Commit af29a92

Browse files
authored
perf(material/tooltip): Tiny but measurable optimization to MatTooltip construction. Defer hooking up to directionality changes until overlay is created. (#30214)
1 parent 9f73fed commit af29a92

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/material/tooltip/tooltip.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
217217
private _currentPosition: TooltipPosition;
218218
private readonly _cssClassPrefix: string = 'mat-mdc';
219219
private _ariaDescriptionPending: boolean;
220+
private _dirSubscribed = false;
220221

221222
/** Allows the user to define the position of the tooltip relative to the parent element */
222223
@Input('matTooltipPosition')
@@ -396,12 +397,6 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
396397
}
397398
}
398399

399-
this._dir.change.pipe(takeUntil(this._destroyed)).subscribe(() => {
400-
if (this._overlayRef) {
401-
this._updatePosition(this._overlayRef);
402-
}
403-
});
404-
405400
this._viewportMargin = MIN_VIEWPORT_TOOLTIP_THRESHOLD;
406401
}
407402

@@ -571,6 +566,15 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
571566
this._overlayRef.addPanelClass(`${this._cssClassPrefix}-tooltip-panel-non-interactive`);
572567
}
573568

569+
if (!this._dirSubscribed) {
570+
this._dirSubscribed = true;
571+
this._dir.change.pipe(takeUntil(this._destroyed)).subscribe(() => {
572+
if (this._overlayRef) {
573+
this._updatePosition(this._overlayRef);
574+
}
575+
});
576+
}
577+
574578
return this._overlayRef;
575579
}
576580

0 commit comments

Comments
 (0)