@@ -11,21 +11,19 @@ import {Directionality} from '@angular/cdk/bidi';
11
11
import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
12
12
import { ESCAPE } from '@angular/cdk/keycodes' ;
13
13
import { BreakpointObserver , Breakpoints , BreakpointState } from '@angular/cdk/layout' ;
14
- import { HammerLoader , HAMMER_LOADER } from '@angular/platform-browser' ;
15
14
import {
16
15
FlexibleConnectedPositionStrategy ,
17
16
HorizontalConnectionPos ,
18
17
OriginConnectionPosition ,
19
18
Overlay ,
20
19
OverlayConnectionPosition ,
21
20
OverlayRef ,
22
- VerticalConnectionPos ,
23
21
ScrollStrategy ,
22
+ VerticalConnectionPos ,
24
23
} from '@angular/cdk/overlay' ;
25
- import { ScrollDispatcher } from '@angular/cdk/scrolling' ;
26
24
import { Platform } from '@angular/cdk/platform' ;
27
25
import { ComponentPortal } from '@angular/cdk/portal' ;
28
- import { take , takeUntil } from 'rxjs/operators ' ;
26
+ import { ScrollDispatcher } from '@angular/cdk/scrolling ' ;
29
27
import {
30
28
ChangeDetectionStrategy ,
31
29
ChangeDetectorRef ,
@@ -37,11 +35,15 @@ import {
37
35
Input ,
38
36
NgZone ,
39
37
OnDestroy ,
38
+ OnInit ,
40
39
Optional ,
41
40
ViewContainerRef ,
42
41
ViewEncapsulation ,
43
42
} from '@angular/core' ;
44
- import { Subject , Observable } from 'rxjs' ;
43
+ import { HAMMER_LOADER , HammerLoader } from '@angular/platform-browser' ;
44
+ import { Observable , Subject } from 'rxjs' ;
45
+ import { take , takeUntil } from 'rxjs/operators' ;
46
+
45
47
import { matTooltipAnimations } from './tooltip-animations' ;
46
48
47
49
@@ -116,7 +118,7 @@ export function MAT_TOOLTIP_DEFAULT_OPTIONS_FACTORY(): MatTooltipDefaultOptions
116
118
'(touchend)' : '_handleTouchend()' ,
117
119
} ,
118
120
} )
119
- export class MatTooltip implements OnDestroy {
121
+ export class MatTooltip implements OnDestroy , OnInit {
120
122
_overlayRef : OverlayRef | null ;
121
123
_tooltipInstance : TooltipComponent | null ;
122
124
@@ -214,7 +216,6 @@ export class MatTooltip implements OnDestroy {
214
216
215
217
this . _scrollStrategy = scrollStrategy ;
216
218
const element : HTMLElement = _elementRef . nativeElement ;
217
- const elementStyle = element . style as CSSStyleDeclaration & { webkitUserDrag : string } ;
218
219
const hasGestures = typeof window === 'undefined' || ( window as any ) . Hammer || hammerLoader ;
219
220
220
221
// The mouse events shouldn't be bound on mobile devices, because they can prevent the
@@ -231,6 +232,27 @@ export class MatTooltip implements OnDestroy {
231
232
232
233
this . _manualListeners . forEach ( ( listener , event ) => element . addEventListener ( event , listener ) ) ;
233
234
235
+ _focusMonitor . monitor ( _elementRef ) . pipe ( takeUntil ( this . _destroyed ) ) . subscribe ( origin => {
236
+ // Note that the focus monitor runs outside the Angular zone.
237
+ if ( ! origin ) {
238
+ _ngZone . run ( ( ) => this . hide ( 0 ) ) ;
239
+ } else if ( origin === 'keyboard' ) {
240
+ _ngZone . run ( ( ) => this . show ( ) ) ;
241
+ }
242
+ } ) ;
243
+
244
+ if ( _defaultOptions && _defaultOptions . position ) {
245
+ this . position = _defaultOptions . position ;
246
+ }
247
+ }
248
+
249
+ /**
250
+ * Setup styling-specific things
251
+ */
252
+ ngOnInit ( ) {
253
+ const element = this . _elementRef . nativeElement ;
254
+ const elementStyle = element . style as CSSStyleDeclaration & { webkitUserDrag : string } ;
255
+
234
256
if ( element . nodeName === 'INPUT' || element . nodeName === 'TEXTAREA' ) {
235
257
// When we bind a gesture event on an element (in this case `longpress`), HammerJS
236
258
// will add some inline styles by default, including `user-select: none`. This is
@@ -246,19 +268,6 @@ export class MatTooltip implements OnDestroy {
246
268
if ( element . draggable && elementStyle . webkitUserDrag === 'none' ) {
247
269
elementStyle . webkitUserDrag = '' ;
248
270
}
249
-
250
- _focusMonitor . monitor ( _elementRef ) . pipe ( takeUntil ( this . _destroyed ) ) . subscribe ( origin => {
251
- // Note that the focus monitor runs outside the Angular zone.
252
- if ( ! origin ) {
253
- _ngZone . run ( ( ) => this . hide ( 0 ) ) ;
254
- } else if ( origin === 'keyboard' ) {
255
- _ngZone . run ( ( ) => this . show ( ) ) ;
256
- }
257
- } ) ;
258
-
259
- if ( _defaultOptions && _defaultOptions . position ) {
260
- this . position = _defaultOptions . position ;
261
- }
262
271
}
263
272
264
273
/**
0 commit comments