mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
committed by
tinayuangao
parent
d2c11ca50b
commit
d66284dcd3
@@ -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);
|
||||
|
||||
|
||||
@@ -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`. */
|
||||
|
||||
Reference in New Issue
Block a user