5
5
* Use of this source code is governed by an MIT-style license that can be
6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
-
9
8
import { animate , AnimationEvent , state , style , transition , trigger } from '@angular/animations' ;
10
- import { AriaDescriber } from '@angular/cdk/a11y' ;
9
+ import { AriaDescriber , FocusMonitor } from '@angular/cdk/a11y' ;
11
10
import { Directionality } from '@angular/cdk/bidi' ;
12
11
import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
13
12
import { ESCAPE } from '@angular/cdk/keycodes' ;
@@ -90,8 +89,6 @@ export const MAT_TOOLTIP_SCROLL_STRATEGY_PROVIDER = {
90
89
exportAs : 'matTooltip' ,
91
90
host : {
92
91
'(longpress)' : 'show()' ,
93
- '(focus)' : 'show()' ,
94
- '(blur)' : 'hide(0)' ,
95
92
'(keydown)' : '_handleKeydown($event)' ,
96
93
'(touchend)' : 'hide(' + TOUCHEND_HIDE_DELAY + ')' ,
97
94
} ,
@@ -177,6 +174,7 @@ export class MatTooltip implements OnDestroy {
177
174
private _ngZone : NgZone ,
178
175
private _platform : Platform ,
179
176
private _ariaDescriber : AriaDescriber ,
177
+ private _focusMonitor : FocusMonitor ,
180
178
@Inject ( MAT_TOOLTIP_SCROLL_STRATEGY ) private _scrollStrategy ,
181
179
@Optional ( ) private _dir : Directionality ) {
182
180
@@ -188,6 +186,15 @@ export class MatTooltip implements OnDestroy {
188
186
this . _leaveListener =
189
187
renderer . listen ( _elementRef . nativeElement , 'mouseleave' , ( ) => this . hide ( ) ) ;
190
188
}
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
+ } ) ;
191
198
}
192
199
193
200
/**
@@ -197,13 +204,15 @@ export class MatTooltip implements OnDestroy {
197
204
if ( this . _tooltipInstance ) {
198
205
this . _disposeTooltip ( ) ;
199
206
}
207
+
200
208
// Clean up the event listeners set in the constructor
201
209
if ( ! this . _platform . IOS ) {
202
210
this . _enterListener ( ) ;
203
211
this . _leaveListener ( ) ;
204
212
}
205
213
206
214
this . _ariaDescriber . removeDescription ( this . _elementRef . nativeElement , this . message ) ;
215
+ this . _focusMonitor . stopMonitoring ( this . _elementRef . nativeElement ) ;
207
216
}
208
217
209
218
/** Shows the tooltip after the delay in ms, defaults to tooltip-delay-show or 0ms if no input */
0 commit comments