@@ -11,21 +11,19 @@ import {Directionality} from '@angular/cdk/bidi';
1111import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
1212import { ESCAPE } from '@angular/cdk/keycodes' ;
1313import { BreakpointObserver , Breakpoints , BreakpointState } from '@angular/cdk/layout' ;
14- import { HammerLoader , HAMMER_LOADER } from '@angular/platform-browser' ;
1514import {
1615 FlexibleConnectedPositionStrategy ,
1716 HorizontalConnectionPos ,
1817 OriginConnectionPosition ,
1918 Overlay ,
2019 OverlayConnectionPosition ,
2120 OverlayRef ,
22- VerticalConnectionPos ,
2321 ScrollStrategy ,
22+ VerticalConnectionPos ,
2423} from '@angular/cdk/overlay' ;
25- import { ScrollDispatcher } from '@angular/cdk/scrolling' ;
2624import { Platform } from '@angular/cdk/platform' ;
2725import { ComponentPortal } from '@angular/cdk/portal' ;
28- import { take , takeUntil } from 'rxjs/operators ' ;
26+ import { ScrollDispatcher } from '@angular/cdk/scrolling ' ;
2927import {
3028 ChangeDetectionStrategy ,
3129 ChangeDetectorRef ,
@@ -37,11 +35,15 @@ import {
3735 Input ,
3836 NgZone ,
3937 OnDestroy ,
38+ OnInit ,
4039 Optional ,
4140 ViewContainerRef ,
4241 ViewEncapsulation ,
4342} 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+
4547import { matTooltipAnimations } from './tooltip-animations' ;
4648
4749
@@ -116,7 +118,7 @@ export function MAT_TOOLTIP_DEFAULT_OPTIONS_FACTORY(): MatTooltipDefaultOptions
116118 '(touchend)' : '_handleTouchend()' ,
117119 } ,
118120} )
119- export class MatTooltip implements OnDestroy {
121+ export class MatTooltip implements OnDestroy , OnInit {
120122 _overlayRef : OverlayRef | null ;
121123 _tooltipInstance : TooltipComponent | null ;
122124
@@ -214,7 +216,6 @@ export class MatTooltip implements OnDestroy {
214216
215217 this . _scrollStrategy = scrollStrategy ;
216218 const element : HTMLElement = _elementRef . nativeElement ;
217- const elementStyle = element . style as CSSStyleDeclaration & { webkitUserDrag : string } ;
218219 const hasGestures = typeof window === 'undefined' || ( window as any ) . Hammer || hammerLoader ;
219220
220221 // The mouse events shouldn't be bound on mobile devices, because they can prevent the
@@ -231,6 +232,27 @@ export class MatTooltip implements OnDestroy {
231232
232233 this . _manualListeners . forEach ( ( listener , event ) => element . addEventListener ( event , listener ) ) ;
233234
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+
234256 if ( element . nodeName === 'INPUT' || element . nodeName === 'TEXTAREA' ) {
235257 // When we bind a gesture event on an element (in this case `longpress`), HammerJS
236258 // will add some inline styles by default, including `user-select: none`. This is
@@ -246,19 +268,6 @@ export class MatTooltip implements OnDestroy {
246268 if ( element . draggable && elementStyle . webkitUserDrag === 'none' ) {
247269 elementStyle . webkitUserDrag = '' ;
248270 }
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- }
262271 }
263272
264273 /**
0 commit comments