@@ -2,7 +2,7 @@ import {Component, ViewChild} from '@angular/core';
2
2
import { By } from '@angular/platform-browser' ;
3
3
import { ComponentFixture , TestBed , async , inject , fakeAsync , tick } from '@angular/core/testing' ;
4
4
import { Directionality } from '@angular/cdk/bidi' ;
5
- import { dispatchKeyboardEvent } from '@angular/cdk/testing' ;
5
+ import { dispatchKeyboardEvent , createKeyboardEvent , dispatchEvent } from '@angular/cdk/testing' ;
6
6
import { ESCAPE , A } from '@angular/cdk/keycodes' ;
7
7
import { CdkConnectedOverlay , OverlayModule , CdkOverlayOrigin } from './index' ;
8
8
import { OverlayContainer } from './overlay-container' ;
@@ -109,11 +109,25 @@ describe('Overlay directives', () => {
109
109
fixture . componentInstance . isOpen = true ;
110
110
fixture . detectChanges ( ) ;
111
111
112
- dispatchKeyboardEvent ( document . body , 'keydown' , ESCAPE ) ;
112
+ const event = dispatchKeyboardEvent ( document . body , 'keydown' , ESCAPE ) ;
113
113
fixture . detectChanges ( ) ;
114
114
115
115
expect ( overlayContainerElement . textContent ! . trim ( ) ) . toBe ( '' ,
116
116
'Expected overlay to have been detached.' ) ;
117
+ expect ( event . defaultPrevented ) . toBe ( true ) ;
118
+ } ) ;
119
+
120
+ it ( 'should not close when pressing escape with a modifier' , ( ) => {
121
+ fixture . componentInstance . isOpen = true ;
122
+ fixture . detectChanges ( ) ;
123
+
124
+ const event = createKeyboardEvent ( 'keydown' , ESCAPE ) ;
125
+ Object . defineProperty ( event , 'altKey' , { get : ( ) => true } ) ;
126
+ dispatchEvent ( document . body , event ) ;
127
+ fixture . detectChanges ( ) ;
128
+
129
+ expect ( overlayContainerElement . textContent ! . trim ( ) ) . toBeTruthy ( ) ;
130
+ expect ( event . defaultPrevented ) . toBe ( false ) ;
117
131
} ) ;
118
132
119
133
it ( 'should not depend on the order in which the `origin` and `open` are set' , async ( ( ) => {
0 commit comments