@@ -16,6 +16,7 @@ import {
16
16
dispatchFakeEvent ,
17
17
dispatchKeyboardEvent ,
18
18
dispatchMouseEvent ,
19
+ createKeyboardEvent ,
19
20
} from '@angular/cdk/testing' ;
20
21
import { Component , DebugElement , Type , ViewChild } from '@angular/core' ;
21
22
import { ComponentFixture , fakeAsync , flush , TestBed } from '@angular/core/testing' ;
@@ -995,7 +996,7 @@ describe('MatSlider', () => {
995
996
expect ( sliderInstance . value ) . toBe ( 0 ) ;
996
997
} ) ;
997
998
998
- it ( `should take not action for presses of keys it doesn't care about` , ( ) => {
999
+ it ( `should take no action for presses of keys it doesn't care about` , ( ) => {
999
1000
sliderInstance . value = 50 ;
1000
1001
1001
1002
expect ( testComponent . onChange ) . not . toHaveBeenCalled ( ) ;
@@ -1008,6 +1009,26 @@ describe('MatSlider', () => {
1008
1009
expect ( testComponent . onChange ) . not . toHaveBeenCalled ( ) ;
1009
1010
expect ( sliderInstance . value ) . toBe ( 50 ) ;
1010
1011
} ) ;
1012
+
1013
+ it ( 'should ignore events modifier keys' , ( ) => {
1014
+ sliderInstance . value = 0 ;
1015
+
1016
+ [
1017
+ UP_ARROW , DOWN_ARROW , RIGHT_ARROW ,
1018
+ LEFT_ARROW , PAGE_DOWN , PAGE_UP , HOME , END
1019
+ ] . forEach ( key => {
1020
+ const event = createKeyboardEvent ( 'keydown' , key ) ;
1021
+ Object . defineProperty ( event , 'altKey' , { get : ( ) => true } ) ;
1022
+ dispatchEvent ( sliderNativeElement , event ) ;
1023
+ fixture . detectChanges ( ) ;
1024
+ expect ( event . defaultPrevented ) . toBe ( false ) ;
1025
+ } ) ;
1026
+
1027
+ expect ( testComponent . onInput ) . not . toHaveBeenCalled ( ) ;
1028
+ expect ( testComponent . onChange ) . not . toHaveBeenCalled ( ) ;
1029
+ expect ( sliderInstance . value ) . toBe ( 0 ) ;
1030
+ } ) ;
1031
+
1011
1032
} ) ;
1012
1033
1013
1034
describe ( 'slider with direction and invert' , ( ) => {
0 commit comments