Skip to content

Commit 6449ae1

Browse files
crisbetojelbourn
authored andcommitted
fix(tooltip): error when updating position while closed (#10704)
Fixes an error that is being thrown when opening a tooltip, closing it and updating its position.
1 parent b4c8443 commit 6449ae1

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/lib/tooltip/tooltip.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,33 @@ describe('MatTooltip', () => {
321321
expect(tooltipDirective._overlayRef!.updatePosition).toHaveBeenCalled();
322322
}));
323323

324+
it('should not throw when updating the position for a closed tooltip', fakeAsync(() => {
325+
tooltipDirective.position = 'left';
326+
tooltipDirective.show(0);
327+
fixture.detectChanges();
328+
tick();
329+
330+
tooltipDirective.hide(0);
331+
fixture.detectChanges();
332+
tick();
333+
334+
// At this point the animation should be able to complete itself and trigger the
335+
// _animationDone function, but for unknown reasons in the test infrastructure,
336+
// this does not occur. Manually call the hook so the animation subscriptions get invoked.
337+
tooltipDirective._tooltipInstance!._animationDone({
338+
fromState: 'visible',
339+
toState: 'hidden',
340+
totalTime: 150,
341+
phaseName: 'done',
342+
} as AnimationEvent);
343+
344+
expect(() => {
345+
tooltipDirective.position = 'right';
346+
fixture.detectChanges();
347+
tick();
348+
}).not.toThrow();
349+
}));
350+
324351
it('should be able to modify the tooltip message', fakeAsync(() => {
325352
assertTooltipInstance(tooltipDirective, false);
326353

src/lib/tooltip/tooltip.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ export class MatTooltip implements OnDestroy {
120120

121121
if (this._overlayRef) {
122122
this._updatePosition();
123-
this._tooltipInstance!.show(value, 0);
123+
124+
if (this._tooltipInstance) {
125+
this._tooltipInstance!.show(value, 0);
126+
}
127+
124128
this._overlayRef.updatePosition();
125129
}
126130
}

0 commit comments

Comments
 (0)