@@ -4,7 +4,7 @@ import {By} from '@angular/platform-browser';
4
4
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
5
5
import { MatExpansionModule , MatExpansionPanel } from './index' ;
6
6
import { SPACE , ENTER } from '@angular/cdk/keycodes' ;
7
- import { dispatchKeyboardEvent } from '@angular/cdk/testing' ;
7
+ import { dispatchKeyboardEvent , createKeyboardEvent , dispatchEvent } from '@angular/cdk/testing' ;
8
8
9
9
10
10
describe ( 'MatExpansionPanel' , ( ) => {
@@ -139,6 +139,24 @@ describe('MatExpansionPanel', () => {
139
139
expect ( event . defaultPrevented ) . toBe ( true ) ;
140
140
} ) ;
141
141
142
+ it ( 'should not toggle if a modifier key is pressed' , ( ) => {
143
+ const fixture = TestBed . createComponent ( PanelWithContent ) ;
144
+ const headerEl = fixture . nativeElement . querySelector ( '.mat-expansion-panel-header' ) ;
145
+
146
+ spyOn ( fixture . componentInstance . panel , 'toggle' ) ;
147
+
148
+ [ 'altKey' , 'metaKey' , 'shiftKey' , 'ctrlKey' ] . forEach ( modifier => {
149
+ const event = createKeyboardEvent ( 'keydown' , ENTER ) ;
150
+ Object . defineProperty ( event , modifier , { get : ( ) => true } ) ;
151
+
152
+ dispatchEvent ( headerEl , event ) ;
153
+ fixture . detectChanges ( ) ;
154
+
155
+ expect ( fixture . componentInstance . panel . toggle ) . not . toHaveBeenCalled ( ) ;
156
+ expect ( event . defaultPrevented ) . toBe ( false ) ;
157
+ } ) ;
158
+ } ) ;
159
+
142
160
it ( 'should not be able to focus content while closed' , fakeAsync ( ( ) => {
143
161
const fixture = TestBed . createComponent ( PanelWithContent ) ;
144
162
fixture . componentInstance . expanded = true ;
0 commit comments