55 * Use of this source code is governed by an MIT-style license that can be
66 * found in the LICENSE file at https://angular.io/license
77 */
8-
98import { animate , AnimationEvent , state , style , transition , trigger } from '@angular/animations' ;
10- import { AriaDescriber } from '@angular/cdk/a11y' ;
9+ import { AriaDescriber , FocusMonitor } from '@angular/cdk/a11y' ;
1110import { Directionality } from '@angular/cdk/bidi' ;
1211import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
1312import { ESCAPE } from '@angular/cdk/keycodes' ;
@@ -90,8 +89,6 @@ export const MAT_TOOLTIP_SCROLL_STRATEGY_PROVIDER = {
9089 exportAs : 'matTooltip' ,
9190 host : {
9291 '(longpress)' : 'show()' ,
93- '(focus)' : 'show()' ,
94- '(blur)' : 'hide(0)' ,
9592 '(keydown)' : '_handleKeydown($event)' ,
9693 '(touchend)' : 'hide(' + TOUCHEND_HIDE_DELAY + ')' ,
9794 } ,
@@ -177,6 +174,7 @@ export class MatTooltip implements OnDestroy {
177174 private _ngZone : NgZone ,
178175 private _platform : Platform ,
179176 private _ariaDescriber : AriaDescriber ,
177+ private _focusMonitor : FocusMonitor ,
180178 @Inject ( MAT_TOOLTIP_SCROLL_STRATEGY ) private _scrollStrategy ,
181179 @Optional ( ) private _dir : Directionality ) {
182180
@@ -188,6 +186,15 @@ export class MatTooltip implements OnDestroy {
188186 this . _leaveListener =
189187 renderer . listen ( _elementRef . nativeElement , 'mouseleave' , ( ) => this . hide ( ) ) ;
190188 }
189+
190+ _focusMonitor . monitor ( _elementRef . nativeElement , renderer , false ) . subscribe ( origin => {
191+ // Note that the focus monitor runs outside the Angular zone.
192+ if ( ! origin ) {
193+ _ngZone . run ( ( ) => this . hide ( 0 ) ) ;
194+ } else if ( origin !== 'program' ) {
195+ _ngZone . run ( ( ) => this . show ( ) ) ;
196+ }
197+ } ) ;
191198 }
192199
193200 /**
@@ -197,13 +204,15 @@ export class MatTooltip implements OnDestroy {
197204 if ( this . _tooltipInstance ) {
198205 this . _disposeTooltip ( ) ;
199206 }
207+
200208 // Clean up the event listeners set in the constructor
201209 if ( ! this . _platform . IOS ) {
202210 this . _enterListener ( ) ;
203211 this . _leaveListener ( ) ;
204212 }
205213
206214 this . _ariaDescriber . removeDescription ( this . _elementRef . nativeElement , this . message ) ;
215+ this . _focusMonitor . stopMonitoring ( this . _elementRef . nativeElement ) ;
207216 }
208217
209218 /** Shows the tooltip after the delay in ms, defaults to tooltip-delay-show or 0ms if no input */
0 commit comments