@@ -268,10 +268,6 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
268
268
this . touchGestures = _defaultOptions . touchGestures ;
269
269
}
270
270
}
271
-
272
- _ngZone . runOutsideAngular ( ( ) => {
273
- _elementRef . nativeElement . addEventListener ( 'keydown' , this . _handleKeydown ) ;
274
- } ) ;
275
271
}
276
272
277
273
ngAfterViewInit ( ) {
@@ -304,7 +300,6 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
304
300
}
305
301
306
302
// Clean up the event listeners set in the constructor
307
- nativeElement . removeEventListener ( 'keydown' , this . _handleKeydown ) ;
308
303
this . _passiveListeners . forEach ( ( listener , event ) => {
309
304
nativeElement . removeEventListener ( event , listener , passiveListenerOptions ) ;
310
305
} ) ;
@@ -353,18 +348,6 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
353
348
return ! ! this . _tooltipInstance && this . _tooltipInstance . isVisible ( ) ;
354
349
}
355
350
356
- /**
357
- * Handles the keydown events on the host element.
358
- * Needs to be an arrow function so that we can use it in addEventListener.
359
- */
360
- private _handleKeydown = ( event : KeyboardEvent ) => {
361
- if ( this . _isTooltipVisible ( ) && event . keyCode === ESCAPE && ! hasModifierKey ( event ) ) {
362
- event . preventDefault ( ) ;
363
- event . stopPropagation ( ) ;
364
- this . _ngZone . run ( ( ) => this . hide ( 0 ) ) ;
365
- }
366
- }
367
-
368
351
/** Create the overlay config and position strategy */
369
352
private _createOverlay ( ) : OverlayRef {
370
353
if ( this . _overlayRef ) {
@@ -392,7 +375,7 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
392
375
}
393
376
} ) ;
394
377
395
- this . _overlayRef = this . _overlay . create ( {
378
+ const overlayRef = this . _overlayRef = this . _overlay . create ( {
396
379
direction : this . _dir ,
397
380
positionStrategy : strategy ,
398
381
panelClass : TOOLTIP_PANEL_CLASS ,
@@ -401,11 +384,21 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
401
384
402
385
this . _updatePosition ( ) ;
403
386
404
- this . _overlayRef . detachments ( )
387
+ overlayRef . keydownEvents ( )
388
+ . pipe ( takeUntil ( this . _destroyed ) )
389
+ . subscribe ( event => {
390
+ if ( this . _isTooltipVisible ( ) && event . keyCode === ESCAPE && ! hasModifierKey ( event ) ) {
391
+ event . preventDefault ( ) ;
392
+ event . stopPropagation ( ) ;
393
+ this . _ngZone . run ( ( ) => this . hide ( 0 ) ) ;
394
+ }
395
+ } ) ;
396
+
397
+ overlayRef . detachments ( )
405
398
. pipe ( takeUntil ( this . _destroyed ) )
406
399
. subscribe ( ( ) => this . _detach ( ) ) ;
407
400
408
- return this . _overlayRef ;
401
+ return overlayRef ;
409
402
}
410
403
411
404
/** Detaches the currently-attached tooltip. */
0 commit comments