@@ -4,7 +4,7 @@ import {By} from '@angular/platform-browser';
44import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
55import { MatExpansionModule , MatExpansionPanel } from './index' ;
66import { SPACE , ENTER } from '@angular/cdk/keycodes' ;
7- import { dispatchKeyboardEvent } from '@angular/cdk/testing' ;
7+ import { dispatchKeyboardEvent , createKeyboardEvent , dispatchEvent } from '@angular/cdk/testing' ;
88
99
1010describe ( 'MatExpansionPanel' , ( ) => {
@@ -139,6 +139,24 @@ describe('MatExpansionPanel', () => {
139139 expect ( event . defaultPrevented ) . toBe ( true ) ;
140140 } ) ;
141141
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+
142160 it ( 'should not be able to focus content while closed' , fakeAsync ( ( ) => {
143161 const fixture = TestBed . createComponent ( PanelWithContent ) ;
144162 fixture . componentInstance . expanded = true ;
0 commit comments