fix(tooltip): close tooltip if message is cleared while open (#8544)

Closes the tooltip if its message is cleared while it is open. Currently it'll continue showing a small grey rectangle under the trigger.
This commit is contained in:
Kristiyan Kostadinov
2017-11-28 20:51:38 +01:00
committed by tinayuangao
parent d2c11ca50b
commit d66284dcd3
2 changed files with 21 additions and 3 deletions
+12
View File
@@ -191,6 +191,18 @@ describe('MatTooltip', () => {
expect(tooltipDirective._isTooltipVisible()).toBe(false);
}));
it('should hide if the message is cleared while the tooltip is open', fakeAsync(() => {
tooltipDirective.show();
fixture.detectChanges();
tick(0);
expect(tooltipDirective._isTooltipVisible()).toBe(true);
fixture.componentInstance.message = '';
fixture.detectChanges();
tick(0);
expect(tooltipDirective._isTooltipVisible()).toBe(false);
}));
it('should not show if hide is called before delay finishes', async(() => {
assertTooltipInstance(tooltipDirective, false);
+9 -3
View File
@@ -142,14 +142,20 @@ export class MatTooltip implements OnDestroy {
private _message = '';
/** The message to be displayed in the tooltip */
@Input('matTooltip') get message() { return this._message; }
@Input('matTooltip')
get message() { return this._message; }
set message(value: string) {
this._ariaDescriber.removeDescription(this._elementRef.nativeElement, this._message);
// If the message is not a string (e.g. number), convert it to a string and trim it.
this._message = value != null ? `${value}`.trim() : '';
this._updateTooltipMessage();
this._ariaDescriber.describe(this._elementRef.nativeElement, this.message);
if (!this._message && this._isTooltipVisible()) {
this.hide(0);
} else {
this._updateTooltipMessage();
this._ariaDescriber.describe(this._elementRef.nativeElement, this.message);
}
}
/** Classes to be passed to the tooltip. Supports the same syntax as `ngClass`. */