File tree Expand file tree Collapse file tree 2 files changed +24
-4
lines changed Expand file tree Collapse file tree 2 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -113,6 +113,26 @@ describe('MatTooltip', () => {
113113 expect ( tooltipDirective . _tooltipInstance ) . toBeNull ( ) ;
114114 } ) ) ;
115115
116+ it ( 'should be able to re-open a tooltip if it was closed by detaching the overlay' ,
117+ fakeAsync ( ( ) => {
118+ tooltipDirective . show ( ) ;
119+ tick ( 0 ) ;
120+ expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( true ) ;
121+ fixture . detectChanges ( ) ;
122+ tick ( 500 ) ;
123+
124+ tooltipDirective . _overlayRef ! . detach ( ) ;
125+ tick ( 0 ) ;
126+ fixture . detectChanges ( ) ;
127+ expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( false ) ;
128+ flushMicrotasks ( ) ;
129+ expect ( tooltipDirective . _tooltipInstance ) . toBeNull ( ) ;
130+
131+ tooltipDirective . show ( ) ;
132+ tick ( 0 ) ;
133+ expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( true ) ;
134+ } ) ) ;
135+
116136 it ( 'should show with delay' , fakeAsync ( ( ) => {
117137 expect ( tooltipDirective . _tooltipInstance ) . toBeUndefined ( ) ;
118138
Original file line number Diff line number Diff line change @@ -255,13 +255,13 @@ export class MatTooltip implements OnDestroy {
255255
256256 /** Create the tooltip to display */
257257 private _createTooltip ( ) : void {
258- let overlayRef = this . _createOverlay ( ) ;
259- let portal = new ComponentPortal ( TooltipComponent , this . _viewContainerRef ) ;
258+ const overlayRef = this . _createOverlay ( ) ;
259+ const portal = new ComponentPortal ( TooltipComponent , this . _viewContainerRef ) ;
260260
261261 this . _tooltipInstance = overlayRef . attach ( portal ) . instance ;
262262
263- // Dispose the overlay when finished the shown tooltip .
264- this . _tooltipInstance ! . afterHidden ( ) . subscribe ( ( ) => {
263+ // Dispose of the tooltip when the overlay is detached .
264+ overlayRef . detachments ( ) . subscribe ( ( ) => {
265265 // Check first if the tooltip has already been removed through this components destroy.
266266 if ( this . _tooltipInstance ) {
267267 this . _disposeTooltip ( ) ;
You can’t perform that action at this time.
0 commit comments