Skip to content

Commit bcedffe

Browse files
committed
perf(material/tooltip): Tiny but measurable optimization to MatTooltip construction. Defer hooking up to directionality changes until overlay is created.
1 parent 5347d8c commit bcedffe

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
@@ -220,6 +220,7 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
220220
private _currentPosition: TooltipPosition;
221221
private readonly _cssClassPrefix: string = 'mat-mdc';
222222
private _ariaDescriptionPending: boolean;
223+
private _dirSubscribed = false;
223224

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

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

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

565+
if (!this._dirSubscribed) {
566+
this._dirSubscribed = true;
567+
this._dir.change.pipe(takeUntil(this._destroyed)).subscribe(() => {
568+
if (this._overlayRef) {
569+
this._updatePosition(this._overlayRef);
570+
}
571+
});
572+
}
573+
570574
return this._overlayRef;
571575
}
572576

0 commit comments

Comments
 (0)