99 OnDestroy ,
1010 Renderer2 ,
1111 ChangeDetectorRef ,
12+ ViewEncapsulation ,
1213} from '@angular/core' ;
1314import {
1415 style ,
@@ -68,6 +69,7 @@ export class MdTooltip implements OnDestroy {
6869
6970 private _position : TooltipPosition = 'below' ;
7071 private _disabled : boolean = false ;
72+ private _tooltipClass : string | string [ ] | Set < string > | { [ key : string ] : any } ;
7173
7274 /** Allows the user to define the position of the tooltip relative to the parent element */
7375 @Input ( 'mdTooltipPosition' )
@@ -118,6 +120,16 @@ export class MdTooltip implements OnDestroy {
118120 }
119121 }
120122
123+ /** Classes to be passed to the tooltip. Supports the same syntax as `ngClass`. */
124+ @Input ( 'mdTooltipClass' )
125+ get tooltipClass ( ) { return this . _tooltipClass ; }
126+ set tooltipClass ( value : string | string [ ] | Set < string > | { [ key : string ] : any } ) {
127+ this . _tooltipClass = value ;
128+ if ( this . _tooltipInstance ) {
129+ this . _setTooltipClass ( this . _tooltipClass ) ;
130+ }
131+ }
132+
121133 /** @deprecated */
122134 @Input ( 'md-tooltip' )
123135 get _deprecatedMessage ( ) : string { return this . message ; }
@@ -148,6 +160,11 @@ export class MdTooltip implements OnDestroy {
148160 get _matShowDelay ( ) { return this . showDelay ; }
149161 set _matShowDelay ( v ) { this . showDelay = v ; }
150162
163+ // Properties with `mat-` prefix for nonconflict mode.
164+ @Input ( 'matTooltipClass' )
165+ get _matClass ( ) { return this . tooltipClass ; }
166+ set _matClass ( v ) { this . tooltipClass = v ; }
167+
151168 constructor (
152169 private _overlay : Overlay ,
153170 private _elementRef : ElementRef ,
@@ -183,6 +200,7 @@ export class MdTooltip implements OnDestroy {
183200 this . _createTooltip ( ) ;
184201 }
185202
203+ this . _setTooltipClass ( this . _tooltipClass ) ;
186204 this . _setTooltipMessage ( this . _message ) ;
187205 this . _tooltipInstance . show ( this . _position , delay ) ;
188206 }
@@ -313,6 +331,12 @@ export class MdTooltip implements OnDestroy {
313331 }
314332 } ) ;
315333 }
334+
335+ /** Updates the tooltip class */
336+ private _setTooltipClass ( tooltipClass : string | string [ ] | Set < string > | { [ key : string ] : any } ) {
337+ this . _tooltipInstance . tooltipClass = tooltipClass ;
338+ this . _tooltipInstance . _markForCheck ( ) ;
339+ }
316340}
317341
318342export type TooltipVisibility = 'initial' | 'visible' | 'hidden' ;
@@ -326,6 +350,7 @@ export type TooltipVisibility = 'initial' | 'visible' | 'hidden';
326350 selector : 'md-tooltip-component, mat-tooltip-component' ,
327351 templateUrl : 'tooltip.html' ,
328352 styleUrls : [ 'tooltip.css' ] ,
353+ encapsulation : ViewEncapsulation . None ,
329354 animations : [
330355 trigger ( 'state' , [
331356 state ( 'void' , style ( { transform : 'scale(0)' } ) ) ,
@@ -344,6 +369,9 @@ export class TooltipComponent {
344369 /** Message to display in the tooltip */
345370 message : string ;
346371
372+ /** Classes to be added to the tooltip. Supports the same syntax as `ngClass`. */
373+ tooltipClass : string | string [ ] | Set < string > | { [ key : string ] : any } ;
374+
347375 /** The timeout ID of any current timer set to show the tooltip */
348376 _showTimeoutId : number ;
349377
0 commit comments