@@ -424,10 +424,8 @@ export type TooltipVisibility = 'initial' | 'visible' | 'hidden';
424
424
changeDetection : ChangeDetectionStrategy . OnPush ,
425
425
animations : [
426
426
trigger ( 'state' , [
427
- state ( 'void' , style ( { transform : 'scale(0)' } ) ) ,
428
- state ( 'initial' , style ( { transform : 'scale(0)' } ) ) ,
427
+ state ( 'initial, void, hidden' , style ( { transform : 'scale(0)' } ) ) ,
429
428
state ( 'visible' , style ( { transform : 'scale(1)' } ) ) ,
430
- state ( 'hidden' , style ( { transform : 'scale(0)' } ) ) ,
431
429
transition ( '* => visible' , animate ( '150ms cubic-bezier(0.0, 0.0, 0.2, 1)' ) ) ,
432
430
transition ( '* => hidden' , animate ( '150ms cubic-bezier(0.4, 0.0, 1, 1)' ) ) ,
433
431
] )
@@ -457,7 +455,7 @@ export class TooltipComponent {
457
455
_visibility : TooltipVisibility = 'initial' ;
458
456
459
457
/** Whether interactions on the page should close the tooltip */
460
- _closeOnInteraction : boolean = false ;
458
+ private _closeOnInteraction : boolean = false ;
461
459
462
460
/** The transform origin used in the animation for showing and hiding the tooltip */
463
461
_transformOrigin : string = 'bottom' ;
@@ -479,21 +477,13 @@ export class TooltipComponent {
479
477
clearTimeout ( this . _hideTimeoutId ) ;
480
478
}
481
479
482
- // Body interactions should cancel the tooltip if there is a delay in showing.
483
- this . _closeOnInteraction = true ;
484
-
485
480
this . _setTransformOrigin ( position ) ;
486
481
this . _showTimeoutId = setTimeout ( ( ) => {
487
482
this . _visibility = 'visible' ;
488
483
489
- // If this was set to true immediately, then a body click that triggers show() would
490
- // trigger interaction and close the tooltip right after it was displayed.
491
- this . _closeOnInteraction = false ;
492
-
493
484
// Mark for check so if any parent component has set the
494
485
// ChangeDetectionStrategy to OnPush it will be checked anyways
495
486
this . _markForCheck ( ) ;
496
- setTimeout ( ( ) => this . _closeOnInteraction = true , 0 ) ;
497
487
} , delay ) ;
498
488
}
499
489
@@ -509,7 +499,6 @@ export class TooltipComponent {
509
499
510
500
this . _hideTimeoutId = setTimeout ( ( ) => {
511
501
this . _visibility = 'hidden' ;
512
- this . _closeOnInteraction = false ;
513
502
514
503
// Mark for check so if any parent component has set the
515
504
// ChangeDetectionStrategy to OnPush it will be checked anyways
@@ -545,10 +534,23 @@ export class TooltipComponent {
545
534
}
546
535
}
547
536
548
- _afterVisibilityAnimation ( e : AnimationEvent ) : void {
549
- if ( e . toState === 'hidden' && ! this . isVisible ( ) ) {
537
+ _animationStart ( ) {
538
+ this . _closeOnInteraction = false ;
539
+ }
540
+
541
+ _animationDone ( event : AnimationEvent ) : void {
542
+ const toState = event . toState as TooltipVisibility ;
543
+
544
+ if ( toState === 'hidden' && ! this . isVisible ( ) ) {
550
545
this . _onHide . next ( ) ;
551
546
}
547
+
548
+ if ( toState === 'visible' || toState === 'hidden' ) {
549
+ // Note: as of Angular 4.3, the animations module seems to fire the `start` callback before
550
+ // the end if animations are disabled. Make this call async to ensure that it still fires
551
+ // at the appropriate time.
552
+ Promise . resolve ( ) . then ( ( ) => this . _closeOnInteraction = true ) ;
553
+ }
552
554
}
553
555
554
556
/**
0 commit comments