Skip to content

Commit 2701aae

Browse files
belevmmalerba
authored andcommitted
fix(tooltip): don't show tooltip if message is empty or not present (#2081)
Closes #2078
1 parent 9d20a34 commit 2701aae

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/lib/tooltip/tooltip.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,30 @@ describe('MdTooltip', () => {
7474
expect(tooltipDirective._tooltipInstance).toBeNull();
7575
}));
7676

77+
it('should not show tooltip if message is not present or empty', fakeAsync(() => {
78+
expect(tooltipDirective._tooltipInstance).toBeUndefined();
79+
80+
tooltipDirective.message = undefined;
81+
fixture.detectChanges();
82+
tooltipDirective.show();
83+
expect(tooltipDirective._tooltipInstance).toBeUndefined();
84+
85+
tooltipDirective.message = null;
86+
fixture.detectChanges();
87+
tooltipDirective.show();
88+
expect(tooltipDirective._tooltipInstance).toBeUndefined();
89+
90+
tooltipDirective.message = '';
91+
fixture.detectChanges();
92+
tooltipDirective.show();
93+
expect(tooltipDirective._tooltipInstance).toBeUndefined();
94+
95+
tooltipDirective.message = ' ';
96+
fixture.detectChanges();
97+
tooltipDirective.show();
98+
expect(tooltipDirective._tooltipInstance).toBeUndefined();
99+
}));
100+
77101
it('should not follow through with hide if show is called after', fakeAsync(() => {
78102
tooltipDirective.show();
79103
expect(tooltipDirective._isTooltipVisible()).toBe(true);

src/lib/tooltip/tooltip.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ export class MdTooltip {
9898

9999
/** Shows the tooltip */
100100
show(): void {
101+
if (!this._message || !this._message.trim()) {
102+
return;
103+
}
104+
101105
if (!this._tooltipInstance) {
102106
this._createTooltip();
103107
}

0 commit comments

Comments
 (0)