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.
This commit is contained in:
Kristiyan Kostadinov
2017-09-19 21:21:50 +02:00
committed by Jeremy Elbourn
parent 244c906f90
commit dcf3b27074
2 changed files with 10 additions and 2 deletions
+9 -1
View File
@@ -19,7 +19,8 @@ import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {Direction, Directionality} from '@angular/cdk/bidi';
import {OverlayContainer, OverlayModule, Scrollable} from '@angular/cdk/overlay';
import {Platform} from '@angular/cdk/platform';
import {dispatchFakeEvent} from '@angular/cdk/testing';
import {dispatchFakeEvent, dispatchKeyboardEvent} from '@angular/cdk/testing';
import {ESCAPE} from '@angular/cdk/keycodes';
import {
MdTooltip,
MdTooltipModule,
@@ -469,6 +470,13 @@ describe('MdTooltip', () => {
expect(overlayContainerElement.textContent).toContain(initialTooltipMessage);
}));
it('should not throw when pressing ESCAPE', fakeAsync(() => {
expect(() => {
dispatchKeyboardEvent(buttonElement, 'keydown', ESCAPE);
fixture.detectChanges();
}).not.toThrow();
}));
});
describe('scrollable usage', () => {
+1 -1
View File
@@ -270,7 +270,7 @@ export class MdTooltip implements OnDestroy {
/** Handles the keydown events on the host element. */
_handleKeydown(e: KeyboardEvent) {
if (this._tooltipInstance!.isVisible() && e.keyCode === ESCAPE) {
if (this._isTooltipVisible() && e.keyCode === ESCAPE) {
e.stopPropagation();
this.hide(0);
}