mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
committed by
Jeremy Elbourn
parent
244c906f90
commit
dcf3b27074
@@ -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', () => {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user