File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -191,6 +191,18 @@ describe('MatTooltip', () => {
191
191
expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( false ) ;
192
192
} ) ) ;
193
193
194
+ it ( 'should hide if the message is cleared while the tooltip is open' , fakeAsync ( ( ) => {
195
+ tooltipDirective . show ( ) ;
196
+ fixture . detectChanges ( ) ;
197
+ tick ( 0 ) ;
198
+ expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( true ) ;
199
+
200
+ fixture . componentInstance . message = '' ;
201
+ fixture . detectChanges ( ) ;
202
+ tick ( 0 ) ;
203
+ expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( false ) ;
204
+ } ) ) ;
205
+
194
206
it ( 'should not show if hide is called before delay finishes' , async ( ( ) => {
195
207
assertTooltipInstance ( tooltipDirective , false ) ;
196
208
Original file line number Diff line number Diff line change @@ -142,14 +142,20 @@ export class MatTooltip implements OnDestroy {
142
142
private _message = '' ;
143
143
144
144
/** The message to be displayed in the tooltip */
145
- @Input ( 'matTooltip' ) get message ( ) { return this . _message ; }
145
+ @Input ( 'matTooltip' )
146
+ get message ( ) { return this . _message ; }
146
147
set message ( value : string ) {
147
148
this . _ariaDescriber . removeDescription ( this . _elementRef . nativeElement , this . _message ) ;
148
149
149
150
// If the message is not a string (e.g. number), convert it to a string and trim it.
150
151
this . _message = value != null ? `${ value } ` . trim ( ) : '' ;
151
- this . _updateTooltipMessage ( ) ;
152
- this . _ariaDescriber . describe ( this . _elementRef . nativeElement , this . message ) ;
152
+
153
+ if ( ! this . _message && this . _isTooltipVisible ( ) ) {
154
+ this . hide ( 0 ) ;
155
+ } else {
156
+ this . _updateTooltipMessage ( ) ;
157
+ this . _ariaDescriber . describe ( this . _elementRef . nativeElement , this . message ) ;
158
+ }
153
159
}
154
160
155
161
/** Classes to be passed to the tooltip. Supports the same syntax as `ngClass`. */
You can’t perform that action at this time.
0 commit comments