@@ -74,6 +74,12 @@ export class MdTooltip {
7474 }
7575 }
7676
77+ /** The default delay in ms before showing the tooltip after show is called */
78+ @Input ( 'tooltipShowDelay' ) showDelay = 0 ;
79+
80+ /** The default delay in ms before hiding the tooltip after hide is called */
81+ @Input ( 'tooltipHideDelay' ) hideDelay = 0 ;
82+
7783 /** The message to be displayed in the tooltip */
7884 private _message : string ;
7985 @Input ( 'md-tooltip' ) get message ( ) {
@@ -97,22 +103,20 @@ export class MdTooltip {
97103 }
98104 }
99105
100- /** Shows the tooltip */
101- show ( ) : void {
102- if ( ! this . _message || ! this . _message . trim ( ) ) {
103- return ;
104- }
106+ /** Shows the tooltip after the delay in ms, defaults to tooltip-delay-show or 0ms if no input */
107+ show ( delay : number = this . showDelay ) : void {
108+ if ( ! this . _message || ! this . _message . trim ( ) ) { return ; }
105109
106110 if ( ! this . _tooltipInstance ) {
107111 this . _createTooltip ( ) ;
108112 }
109113
110114 this . _setTooltipMessage ( this . _message ) ;
111- this . _tooltipInstance . show ( this . _position ) ;
115+ this . _tooltipInstance . show ( this . _position , delay ) ;
112116 }
113117
114- /** Hides the tooltip after the provided delay in ms, defaulting to 0ms. */
115- hide ( delay = 0 ) : void {
118+ /** Hides the tooltip after the delay in ms, defaults to tooltip-delay-hide or 0ms if no input */
119+ hide ( delay : number = this . hideDelay ) : void {
116120 if ( this . _tooltipInstance ) {
117121 this . _tooltipInstance . hide ( delay ) ;
118122 }
@@ -222,7 +226,7 @@ export class MdTooltip {
222226 }
223227}
224228
225- export type TooltipVisibility = 'visible' | 'hidden' ;
229+ export type TooltipVisibility = 'initial' | ' visible' | 'hidden' ;
226230
227231@Component ( {
228232 moduleId : module . id ,
@@ -232,6 +236,7 @@ export type TooltipVisibility = 'visible' | 'hidden';
232236 animations : [
233237 trigger ( 'state' , [
234238 state ( 'void' , style ( { transform : 'scale(0)' } ) ) ,
239+ state ( 'initial' , style ( { transform : 'scale(0)' } ) ) ,
235240 state ( 'visible' , style ( { transform : 'scale(1)' } ) ) ,
236241 state ( 'hidden' , style ( { transform : 'scale(0)' } ) ) ,
237242 transition ( '* => visible' , animate ( '150ms cubic-bezier(0.0, 0.0, 0.2, 1)' ) ) ,
@@ -246,11 +251,14 @@ export class TooltipComponent {
246251 /** Message to display in the tooltip */
247252 message : string ;
248253
254+ /** The timeout ID of any current timer set to show the tooltip */
255+ _showTimeoutId : number ;
256+
249257 /** The timeout ID of any current timer set to hide the tooltip */
250258 _hideTimeoutId : number ;
251259
252260 /** Property watched by the animation framework to show or hide the tooltip */
253- _visibility : TooltipVisibility ;
261+ _visibility : TooltipVisibility = 'initial' ;
254262
255263 /** Whether interactions on the page should close the tooltip */
256264 _closeOnInteraction : boolean = false ;
@@ -264,23 +272,33 @@ export class TooltipComponent {
264272 constructor ( @Optional ( ) private _dir : Dir ) { }
265273
266274 /** Shows the tooltip with an animation originating from the provided origin */
267- show ( position : TooltipPosition ) : void {
268- this . _closeOnInteraction = false ;
269- this . _visibility = 'visible' ;
270- this . _setTransformOrigin ( position ) ;
271-
275+ show ( position : TooltipPosition , delay : number ) : void {
272276 // Cancel the delayed hide if it is scheduled
273277 if ( this . _hideTimeoutId ) {
274278 clearTimeout ( this . _hideTimeoutId ) ;
275279 }
276280
277- // If this was set to true immediately, then the body click would trigger interaction and
278- // close the tooltip right after it was displayed.
279- setTimeout ( ( ) => { this . _closeOnInteraction = true ; } , 0 ) ;
281+ // Body interactions should cancel the tooltip if there is a delay in showing.
282+ this . _closeOnInteraction = true ;
283+
284+ this . _setTransformOrigin ( position ) ;
285+ this . _showTimeoutId = setTimeout ( ( ) => {
286+ this . _visibility = 'visible' ;
287+
288+ // If this was set to true immediately, then a body click that triggers show() would
289+ // trigger interaction and close the tooltip right after it was displayed.
290+ this . _closeOnInteraction = false ;
291+ setTimeout ( ( ) => { this . _closeOnInteraction = true ; } , 0 ) ;
292+ } , delay ) ;
280293 }
281294
282295 /** Begins the animation to hide the tooltip after the provided delay in ms */
283296 hide ( delay : number ) : void {
297+ // Cancel the delayed show if it is scheduled
298+ if ( this . _showTimeoutId ) {
299+ clearTimeout ( this . _showTimeoutId ) ;
300+ }
301+
284302 this . _hideTimeoutId = setTimeout ( ( ) => {
285303 this . _visibility = 'hidden' ;
286304 this . _closeOnInteraction = false ;
0 commit comments