Skip to content

fix(tooltip): error when updating position while closed #10704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/lib/tooltip/tooltip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,33 @@ describe('MatTooltip', () => {
expect(tooltipDirective._overlayRef!.updatePosition).toHaveBeenCalled();
}));

it('should not throw when updating the position for a closed tooltip', fakeAsync(() => {
tooltipDirective.position = 'left';
tooltipDirective.show(0);
fixture.detectChanges();
tick();

tooltipDirective.hide(0);
fixture.detectChanges();
tick();

// At this point the animation should be able to complete itself and trigger the
// _animationDone function, but for unknown reasons in the test infrastructure,
// this does not occur. Manually call the hook so the animation subscriptions get invoked.
tooltipDirective._tooltipInstance!._animationDone({
fromState: 'visible',
toState: 'hidden',
totalTime: 150,
phaseName: 'done',
} as AnimationEvent);

expect(() => {
tooltipDirective.position = 'right';
fixture.detectChanges();
tick();
}).not.toThrow();
}));

it('should be able to modify the tooltip message', fakeAsync(() => {
assertTooltipInstance(tooltipDirective, false);

Expand Down
6 changes: 5 additions & 1 deletion src/lib/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ export class MatTooltip implements OnDestroy {

if (this._overlayRef) {
this._updatePosition();
this._tooltipInstance!.show(value, 0);

if (this._tooltipInstance) {
this._tooltipInstance!.show(value, 0);
}

this._overlayRef.updatePosition();
}
}
Expand Down