@@ -76,6 +76,12 @@ describe('MdHorizontalStepper', () => {
76
76
checkKeyboardEvent ( stepperComponent , fixture , stepHeaders ) ;
77
77
} ) ;
78
78
79
+ it ( 'should not set focus on header of selected step if header is not clicked' , ( ) => {
80
+ let stepHeaderEl = fixture . debugElement
81
+ . queryAll ( By . css ( '.mat-horizontal-stepper-header' ) ) [ 1 ] . nativeElement ;
82
+ checkStepHeaderFocusNotCalled ( stepHeaderEl , stepperComponent , fixture ) ;
83
+ } ) ;
84
+
79
85
it ( 'should only be able to return to a previous step if it is editable' , ( ) => {
80
86
checkEditableStep ( stepperComponent , fixture ) ;
81
87
} ) ;
@@ -116,6 +122,12 @@ describe('MdHorizontalStepper', () => {
116
122
checkLinearStepperValidity ( stepHeaderEl , stepperComponent , testComponent , fixture ) ;
117
123
} ) ;
118
124
125
+ it ( 'should not focus step header upon click if it is not able to be selected' , ( ) => {
126
+ let stepHeaderEl = fixture . debugElement
127
+ . queryAll ( By . css ( '.mat-horizontal-stepper-header' ) ) [ 1 ] . nativeElement ;
128
+ checkStepHeaderBlur ( stepHeaderEl , fixture ) ;
129
+ } ) ;
130
+
119
131
it ( 'should be able to move to next step even when invalid if current step is optional' , ( ) => {
120
132
checkOptionalStep ( stepperComponent , testComponent , fixture ) ;
121
133
} ) ;
@@ -188,6 +200,12 @@ describe('MdVerticalStepper', () => {
188
200
checkKeyboardEvent ( stepperComponent , fixture , stepHeaders ) ;
189
201
} ) ;
190
202
203
+ it ( 'should not set focus on header of selected step if header is not clicked' , ( ) => {
204
+ let stepHeaderEl = fixture . debugElement
205
+ . queryAll ( By . css ( '.mat-vertical-stepper-header' ) ) [ 1 ] . nativeElement ;
206
+ checkStepHeaderFocusNotCalled ( stepHeaderEl , stepperComponent , fixture ) ;
207
+ } ) ;
208
+
191
209
it ( 'should only be able to return to a previous step if it is editable' , ( ) => {
192
210
checkEditableStep ( stepperComponent , fixture ) ;
193
211
} ) ;
@@ -229,6 +247,12 @@ describe('MdVerticalStepper', () => {
229
247
checkLinearStepperValidity ( stepHeaderEl , stepperComponent , testComponent , fixture ) ;
230
248
} ) ;
231
249
250
+ it ( 'should not focus step header upon click if it is not able to be selected' , ( ) => {
251
+ let stepHeaderEl = fixture . debugElement
252
+ . queryAll ( By . css ( '.mat-vertical-stepper-header' ) ) [ 1 ] . nativeElement ;
253
+ checkStepHeaderBlur ( stepHeaderEl , fixture ) ;
254
+ } ) ;
255
+
232
256
it ( 'should be able to move to next step even when invalid if current step is optional' , ( ) => {
233
257
checkOptionalStep ( stepperComponent , testComponent , fixture ) ;
234
258
} ) ;
@@ -415,6 +439,19 @@ function checkKeyboardEvent(stepperComponent: MdStepper,
415
439
'Expected index of selected step to change to index of focused step after SPACE event.' ) ;
416
440
}
417
441
442
+ function checkStepHeaderFocusNotCalled ( stepHeaderEl : HTMLElement ,
443
+ stepperComponent : MdStepper ,
444
+ fixture : ComponentFixture < any > ) {
445
+ let nextButtonNativeEl = fixture . debugElement
446
+ . queryAll ( By . directive ( MdStepperNext ) ) [ 0 ] . nativeElement ;
447
+ spyOn ( stepHeaderEl , 'focus' ) ;
448
+ nextButtonNativeEl . click ( ) ;
449
+ fixture . detectChanges ( ) ;
450
+
451
+ expect ( stepperComponent . selectedIndex ) . toBe ( 1 ) ;
452
+ expect ( stepHeaderEl . focus ) . not . toHaveBeenCalled ( ) ;
453
+ }
454
+
418
455
function checkLinearStepperValidity ( stepHeaderEl : HTMLElement ,
419
456
stepperComponent : MdStepper ,
420
457
testComponent :
@@ -440,6 +477,14 @@ function checkLinearStepperValidity(stepHeaderEl: HTMLElement,
440
477
expect ( stepperComponent . selectedIndex ) . toBe ( 1 ) ;
441
478
}
442
479
480
+ function checkStepHeaderBlur ( stepHeaderEl : HTMLElement , fixture : ComponentFixture < any > ) {
481
+ spyOn ( stepHeaderEl , 'blur' ) ;
482
+ stepHeaderEl . click ( ) ;
483
+ fixture . detectChanges ( ) ;
484
+
485
+ expect ( stepHeaderEl . blur ) . toHaveBeenCalled ( ) ;
486
+ }
487
+
443
488
function checkEditableStep ( stepperComponent : MdStepper ,
444
489
fixture : ComponentFixture < any > ) {
445
490
stepperComponent . selectedIndex = 1 ;
0 commit comments