@@ -76,6 +76,12 @@ describe('MdHorizontalStepper', () => {
7676 checkKeyboardEvent ( stepperComponent , fixture , stepHeaders ) ;
7777 } ) ;
7878
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+
7985 it ( 'should only be able to return to a previous step if it is editable' , ( ) => {
8086 checkEditableStep ( stepperComponent , fixture ) ;
8187 } ) ;
@@ -116,6 +122,12 @@ describe('MdHorizontalStepper', () => {
116122 checkLinearStepperValidity ( stepHeaderEl , stepperComponent , testComponent , fixture ) ;
117123 } ) ;
118124
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+
119131 it ( 'should be able to move to next step even when invalid if current step is optional' , ( ) => {
120132 checkOptionalStep ( stepperComponent , testComponent , fixture ) ;
121133 } ) ;
@@ -188,6 +200,12 @@ describe('MdVerticalStepper', () => {
188200 checkKeyboardEvent ( stepperComponent , fixture , stepHeaders ) ;
189201 } ) ;
190202
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+
191209 it ( 'should only be able to return to a previous step if it is editable' , ( ) => {
192210 checkEditableStep ( stepperComponent , fixture ) ;
193211 } ) ;
@@ -229,6 +247,12 @@ describe('MdVerticalStepper', () => {
229247 checkLinearStepperValidity ( stepHeaderEl , stepperComponent , testComponent , fixture ) ;
230248 } ) ;
231249
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+
232256 it ( 'should be able to move to next step even when invalid if current step is optional' , ( ) => {
233257 checkOptionalStep ( stepperComponent , testComponent , fixture ) ;
234258 } ) ;
@@ -415,6 +439,19 @@ function checkKeyboardEvent(stepperComponent: MdStepper,
415439 'Expected index of selected step to change to index of focused step after SPACE event.' ) ;
416440}
417441
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+
418455function checkLinearStepperValidity ( stepHeaderEl : HTMLElement ,
419456 stepperComponent : MdStepper ,
420457 testComponent :
@@ -440,6 +477,14 @@ function checkLinearStepperValidity(stepHeaderEl: HTMLElement,
440477 expect ( stepperComponent . selectedIndex ) . toBe ( 1 ) ;
441478}
442479
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+
443488function checkEditableStep ( stepperComponent : MdStepper ,
444489 fixture : ComponentFixture < any > ) {
445490 stepperComponent . selectedIndex = 1 ;
0 commit comments