Skip to content

Commit

Permalink
fix(tooltip): error on trigger escape presses while closed (#7028)
Browse files Browse the repository at this point in the history
Fixes an error being thrown when pressing escape on a tooltip trigger that isn't showing a tooltip.

Fixes #7009.
  • Loading branch information
crisbeto authored and jelbourn committed Sep 19, 2017
1 parent 244c906 commit dcf3b27
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/lib/tooltip/tooltip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit dcf3b27

Please sign in to comment.