@@ -17,6 +17,7 @@ import {
17
17
OnDestroy ,
18
18
Renderer2 ,
19
19
ChangeDetectorRef ,
20
+ ViewEncapsulation ,
20
21
} from '@angular/core' ;
21
22
import {
22
23
style ,
@@ -75,6 +76,7 @@ export class MdTooltip implements OnDestroy {
75
76
76
77
private _position : TooltipPosition = 'below' ;
77
78
private _disabled : boolean = false ;
79
+ private _tooltipClass : string | string [ ] | Set < string > | { [ key : string ] : any } ;
78
80
79
81
/** Allows the user to define the position of the tooltip relative to the parent element */
80
82
@Input ( 'mdTooltipPosition' )
@@ -125,6 +127,16 @@ export class MdTooltip implements OnDestroy {
125
127
}
126
128
}
127
129
130
+ /** Classes to be passed to the tooltip. Supports the same syntax as `ngClass`. */
131
+ @Input ( 'mdTooltipClass' )
132
+ get tooltipClass ( ) { return this . _tooltipClass ; }
133
+ set tooltipClass ( value : string | string [ ] | Set < string > | { [ key : string ] : any } ) {
134
+ this . _tooltipClass = value ;
135
+ if ( this . _tooltipInstance ) {
136
+ this . _setTooltipClass ( this . _tooltipClass ) ;
137
+ }
138
+ }
139
+
128
140
/** @deprecated */
129
141
@Input ( 'md-tooltip' )
130
142
get _deprecatedMessage ( ) : string { return this . message ; }
@@ -155,6 +167,11 @@ export class MdTooltip implements OnDestroy {
155
167
get _matShowDelay ( ) { return this . showDelay ; }
156
168
set _matShowDelay ( v ) { this . showDelay = v ; }
157
169
170
+ // Properties with `mat-` prefix for nonconflict mode.
171
+ @Input ( 'matTooltipClass' )
172
+ get _matClass ( ) { return this . tooltipClass ; }
173
+ set _matClass ( v ) { this . tooltipClass = v ; }
174
+
158
175
constructor (
159
176
private _overlay : Overlay ,
160
177
private _elementRef : ElementRef ,
@@ -190,6 +207,7 @@ export class MdTooltip implements OnDestroy {
190
207
this . _createTooltip ( ) ;
191
208
}
192
209
210
+ this . _setTooltipClass ( this . _tooltipClass ) ;
193
211
this . _setTooltipMessage ( this . _message ) ;
194
212
this . _tooltipInstance . show ( this . _position , delay ) ;
195
213
}
@@ -322,6 +340,12 @@ export class MdTooltip implements OnDestroy {
322
340
}
323
341
} ) ;
324
342
}
343
+
344
+ /** Updates the tooltip class */
345
+ private _setTooltipClass ( tooltipClass : string | string [ ] | Set < string > | { [ key : string ] : any } ) {
346
+ this . _tooltipInstance . tooltipClass = tooltipClass ;
347
+ this . _tooltipInstance . _markForCheck ( ) ;
348
+ }
325
349
}
326
350
327
351
export type TooltipVisibility = 'initial' | 'visible' | 'hidden' ;
@@ -335,6 +359,7 @@ export type TooltipVisibility = 'initial' | 'visible' | 'hidden';
335
359
selector : 'md-tooltip-component, mat-tooltip-component' ,
336
360
templateUrl : 'tooltip.html' ,
337
361
styleUrls : [ 'tooltip.css' ] ,
362
+ encapsulation : ViewEncapsulation . None ,
338
363
animations : [
339
364
trigger ( 'state' , [
340
365
state ( 'void' , style ( { transform : 'scale(0)' } ) ) ,
@@ -356,6 +381,9 @@ export class TooltipComponent {
356
381
/** Message to display in the tooltip */
357
382
message : string ;
358
383
384
+ /** Classes to be added to the tooltip. Supports the same syntax as `ngClass`. */
385
+ tooltipClass : string | string [ ] | Set < string > | { [ key : string ] : any } ;
386
+
359
387
/** The timeout ID of any current timer set to show the tooltip */
360
388
_showTimeoutId : number ;
361
389
0 commit comments