@@ -144,6 +144,7 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
144
144
private _disabled : boolean = false ;
145
145
private _tooltipClass : string | string [ ] | Set < string > | { [ key : string ] : any } ;
146
146
private _scrollStrategy : ( ) => ScrollStrategy ;
147
+ private _viewInitialized = false ;
147
148
148
149
/** Allows the user to define the position of the tooltip relative to the parent element */
149
150
@Input ( 'matTooltipPosition' )
@@ -173,6 +174,8 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
173
174
// If tooltip is disabled, hide immediately.
174
175
if ( this . _disabled ) {
175
176
this . hide ( 0 ) ;
177
+ } else {
178
+ this . _setupPointerEvents ( ) ;
176
179
}
177
180
}
178
181
@@ -202,14 +205,17 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
202
205
@Input ( 'matTooltip' )
203
206
get message ( ) { return this . _message ; }
204
207
set message ( value : string ) {
205
- this . _ariaDescriber . removeDescription ( this . _elementRef . nativeElement , this . _message ) ;
208
+ if ( this . _message ) {
209
+ this . _ariaDescriber . removeDescription ( this . _elementRef . nativeElement , this . _message ) ;
210
+ }
206
211
207
212
// If the message is not a string (e.g. number), convert it to a string and trim it.
208
213
this . _message = value != null ? `${ value } ` . trim ( ) : '' ;
209
214
210
215
if ( ! this . _message && this . _isTooltipVisible ( ) ) {
211
216
this . hide ( 0 ) ;
212
217
} else {
218
+ this . _setupPointerEvents ( ) ;
213
219
this . _updateTooltipMessage ( ) ;
214
220
this . _ngZone . runOutsideAngular ( ( ) => {
215
221
// The `AriaDescriber` has some functionality that avoids adding a description if it's the
@@ -276,6 +282,7 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
276
282
277
283
ngAfterViewInit ( ) {
278
284
// This needs to happen after view init so the initial values for all inputs have been set.
285
+ this . _viewInitialized = true ;
279
286
this . _setupPointerEvents ( ) ;
280
287
281
288
this . _focusMonitor . monitor ( this . _elementRef )
@@ -543,6 +550,12 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
543
550
544
551
/** Binds the pointer events to the tooltip trigger. */
545
552
private _setupPointerEvents ( ) {
553
+ // Optimization: Defer hooking up events if there's no message or the tooltip is disabled.
554
+ if ( this . _disabled || ! this . message || ! this . _viewInitialized ||
555
+ this . _passiveListeners . size ) {
556
+ return ;
557
+ }
558
+
546
559
// The mouse events shouldn't be bound on mobile devices, because they can prevent the
547
560
// first tap from firing its click event or can cause the tooltip to open for clicks.
548
561
if ( ! this . _platform . IOS && ! this . _platform . ANDROID ) {
0 commit comments