Skip to content

Commit dcf3b27

Browse files
crisbetojelbourn
authored andcommitted
fix(tooltip): error on trigger escape presses while closed (#7028)
Fixes an error being thrown when pressing escape on a tooltip trigger that isn't showing a tooltip. Fixes #7009.
1 parent 244c906 commit dcf3b27

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/lib/tooltip/tooltip.spec.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import {NoopAnimationsModule} from '@angular/platform-browser/animations';
1919
import {Direction, Directionality} from '@angular/cdk/bidi';
2020
import {OverlayContainer, OverlayModule, Scrollable} from '@angular/cdk/overlay';
2121
import {Platform} from '@angular/cdk/platform';
22-
import {dispatchFakeEvent} from '@angular/cdk/testing';
22+
import {dispatchFakeEvent, dispatchKeyboardEvent} from '@angular/cdk/testing';
23+
import {ESCAPE} from '@angular/cdk/keycodes';
2324
import {
2425
MdTooltip,
2526
MdTooltipModule,
@@ -469,6 +470,13 @@ describe('MdTooltip', () => {
469470
expect(overlayContainerElement.textContent).toContain(initialTooltipMessage);
470471
}));
471472

473+
it('should not throw when pressing ESCAPE', fakeAsync(() => {
474+
expect(() => {
475+
dispatchKeyboardEvent(buttonElement, 'keydown', ESCAPE);
476+
fixture.detectChanges();
477+
}).not.toThrow();
478+
}));
479+
472480
});
473481

474482
describe('scrollable usage', () => {

src/lib/tooltip/tooltip.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export class MdTooltip implements OnDestroy {
270270

271271
/** Handles the keydown events on the host element. */
272272
_handleKeydown(e: KeyboardEvent) {
273-
if (this._tooltipInstance!.isVisible() && e.keyCode === ESCAPE) {
273+
if (this._isTooltipVisible() && e.keyCode === ESCAPE) {
274274
e.stopPropagation();
275275
this.hide(0);
276276
}

0 commit comments

Comments
 (0)