Skip to content

Commit

Permalink
fix(tooltip): don't show tooltip if message is empty or not present (#…
Browse files Browse the repository at this point in the history
…2081)

Closes #2078
  • Loading branch information
belev authored and mmalerba committed Dec 6, 2016
1 parent 9d20a34 commit 2701aae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/lib/tooltip/tooltip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@ describe('MdTooltip', () => {
expect(tooltipDirective._tooltipInstance).toBeNull();
}));

it('should not show tooltip if message is not present or empty', fakeAsync(() => {
expect(tooltipDirective._tooltipInstance).toBeUndefined();

tooltipDirective.message = undefined;
fixture.detectChanges();
tooltipDirective.show();
expect(tooltipDirective._tooltipInstance).toBeUndefined();

tooltipDirective.message = null;
fixture.detectChanges();
tooltipDirective.show();
expect(tooltipDirective._tooltipInstance).toBeUndefined();

tooltipDirective.message = '';
fixture.detectChanges();
tooltipDirective.show();
expect(tooltipDirective._tooltipInstance).toBeUndefined();

tooltipDirective.message = ' ';
fixture.detectChanges();
tooltipDirective.show();
expect(tooltipDirective._tooltipInstance).toBeUndefined();
}));

it('should not follow through with hide if show is called after', fakeAsync(() => {
tooltipDirective.show();
expect(tooltipDirective._isTooltipVisible()).toBe(true);
Expand Down
4 changes: 4 additions & 0 deletions src/lib/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export class MdTooltip {

/** Shows the tooltip */
show(): void {
if (!this._message || !this._message.trim()) {
return;
}

if (!this._tooltipInstance) {
this._createTooltip();
}
Expand Down

0 comments on commit 2701aae

Please sign in to comment.