@@ -404,10 +404,8 @@ export type TooltipVisibility = 'initial' | 'visible' | 'hidden';
404
404
changeDetection : ChangeDetectionStrategy . OnPush ,
405
405
animations : [
406
406
trigger ( 'state' , [
407
- state ( 'void' , style ( { transform : 'scale(0)' } ) ) ,
408
- state ( 'initial' , style ( { transform : 'scale(0)' } ) ) ,
407
+ state ( 'initial, void, hidden' , style ( { transform : 'scale(0)' } ) ) ,
409
408
state ( 'visible' , style ( { transform : 'scale(1)' } ) ) ,
410
- state ( 'hidden' , style ( { transform : 'scale(0)' } ) ) ,
411
409
transition ( '* => visible' , animate ( '150ms cubic-bezier(0.0, 0.0, 0.2, 1)' ) ) ,
412
410
transition ( '* => hidden' , animate ( '150ms cubic-bezier(0.4, 0.0, 1, 1)' ) ) ,
413
411
] )
@@ -436,7 +434,7 @@ export class TooltipComponent {
436
434
_visibility : TooltipVisibility = 'initial' ;
437
435
438
436
/** Whether interactions on the page should close the tooltip */
439
- _closeOnInteraction : boolean = false ;
437
+ private _closeOnInteraction : boolean = false ;
440
438
441
439
/** The transform origin used in the animation for showing and hiding the tooltip */
442
440
_transformOrigin : string = 'bottom' ;
@@ -458,21 +456,13 @@ export class TooltipComponent {
458
456
clearTimeout ( this . _hideTimeoutId ) ;
459
457
}
460
458
461
- // Body interactions should cancel the tooltip if there is a delay in showing.
462
- this . _closeOnInteraction = true ;
463
-
464
459
this . _setTransformOrigin ( position ) ;
465
460
this . _showTimeoutId = setTimeout ( ( ) => {
466
461
this . _visibility = 'visible' ;
467
462
468
- // If this was set to true immediately, then a body click that triggers show() would
469
- // trigger interaction and close the tooltip right after it was displayed.
470
- this . _closeOnInteraction = false ;
471
-
472
463
// Mark for check so if any parent component has set the
473
464
// ChangeDetectionStrategy to OnPush it will be checked anyways
474
465
this . _markForCheck ( ) ;
475
- setTimeout ( ( ) => this . _closeOnInteraction = true , 0 ) ;
476
466
} , delay ) ;
477
467
}
478
468
@@ -488,7 +478,6 @@ export class TooltipComponent {
488
478
489
479
this . _hideTimeoutId = setTimeout ( ( ) => {
490
480
this . _visibility = 'hidden' ;
491
- this . _closeOnInteraction = false ;
492
481
493
482
// Mark for check so if any parent component has set the
494
483
// ChangeDetectionStrategy to OnPush it will be checked anyways
@@ -524,10 +513,23 @@ export class TooltipComponent {
524
513
}
525
514
}
526
515
527
- _afterVisibilityAnimation ( e : AnimationEvent ) : void {
528
- if ( e . toState === 'hidden' && ! this . isVisible ( ) ) {
516
+ _animationStart ( ) {
517
+ this . _closeOnInteraction = false ;
518
+ }
519
+
520
+ _animationDone ( event : AnimationEvent ) : void {
521
+ const toState = event . toState as TooltipVisibility ;
522
+
523
+ if ( toState === 'hidden' && ! this . isVisible ( ) ) {
529
524
this . _onHide . next ( ) ;
530
525
}
526
+
527
+ if ( toState === 'visible' || toState === 'hidden' ) {
528
+ // Note: as of Angular 4.3, the animations module seems to fire the `start` callback before
529
+ // the end if animations are disabled. Make this call async to ensure that it still fires
530
+ // at the appropriate time.
531
+ Promise . resolve ( ) . then ( ( ) => this . _closeOnInteraction = true ) ;
532
+ }
531
533
}
532
534
533
535
/**
0 commit comments