@@ -543,6 +543,7 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
543543 panelClass : this . _overlayPanelClass ? [ ...this . _overlayPanelClass , panelClass ] : panelClass ,
544544 scrollStrategy : this . _injector . get ( MAT_TOOLTIP_SCROLL_STRATEGY ) ( ) ,
545545 disableAnimations : this . _animationsDisabled ,
546+ eventPredicate : this . _overlayEventPredicate ,
546547 } ) ;
547548
548549 this . _updatePosition ( this . _overlayRef ) ;
@@ -561,11 +562,10 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
561562 . keydownEvents ( )
562563 . pipe ( takeUntil ( this . _destroyed ) )
563564 . subscribe ( event => {
564- if ( this . _isTooltipVisible ( ) && event . keyCode === ESCAPE && ! hasModifierKey ( event ) ) {
565- event . preventDefault ( ) ;
566- event . stopPropagation ( ) ;
567- this . _ngZone . run ( ( ) => this . hide ( 0 ) ) ;
568- }
565+ // Note: we don't check the `keyCode` since it's covered by the `eventPredicate` above.
566+ event . preventDefault ( ) ;
567+ event . stopPropagation ( ) ;
568+ this . _ngZone . run ( ( ) => this . hide ( 0 ) ) ;
569569 } ) ;
570570
571571 if ( this . _defaultOptions ?. disableTooltipInteractivity ) {
@@ -935,6 +935,18 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
935935 ) ;
936936 }
937937 }
938+
939+ /** Determines which events should be routed to the tooltip overlay. */
940+ private _overlayEventPredicate = ( event : Event ) => {
941+ if ( event . type === 'keydown' ) {
942+ return (
943+ this . _isTooltipVisible ( ) &&
944+ ( event as KeyboardEvent ) . keyCode === ESCAPE &&
945+ ! hasModifierKey ( event as KeyboardEvent )
946+ ) ;
947+ }
948+ return true ;
949+ } ;
938950}
939951
940952/**
0 commit comments