File tree 2 files changed +24
-4
lines changed
2 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -113,6 +113,26 @@ describe('MatTooltip', () => {
113
113
expect ( tooltipDirective . _tooltipInstance ) . toBeNull ( ) ;
114
114
} ) ) ;
115
115
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
+
116
136
it ( 'should show with delay' , fakeAsync ( ( ) => {
117
137
expect ( tooltipDirective . _tooltipInstance ) . toBeUndefined ( ) ;
118
138
Original file line number Diff line number Diff line change @@ -255,13 +255,13 @@ export class MatTooltip implements OnDestroy {
255
255
256
256
/** Create the tooltip to display */
257
257
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 ) ;
260
260
261
261
this . _tooltipInstance = overlayRef . attach ( portal ) . instance ;
262
262
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 ( ( ) => {
265
265
// Check first if the tooltip has already been removed through this components destroy.
266
266
if ( this . _tooltipInstance ) {
267
267
this . _disposeTooltip ( ) ;
You can’t perform that action at this time.
0 commit comments