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