diff --git a/src/cdk/stepper/stepper.ts b/src/cdk/stepper/stepper.ts index 9bb879647d7e..31242d557228 100644 --- a/src/cdk/stepper/stepper.ts +++ b/src/cdk/stepper/stepper.ts @@ -109,9 +109,12 @@ export class CdkStepper { @Input() get selectedIndex() { return this._selectedIndex; } set selectedIndex(index: number) { - if (this._selectedIndex != index && !this._anyControlsInvalid(index)) { + if (this._anyControlsInvalid(index)) { + // remove focus from clicked step header if the step is not able to be selected + this._stepHeader.toArray()[index].nativeElement.blur(); + } else if (this._selectedIndex != index) { this._emitStepperSelectionEvent(index); - this._focusStep(this._selectedIndex); + this._focusIndex = this._selectedIndex; } } private _selectedIndex: number = 0; diff --git a/src/lib/stepper/_stepper-theme.scss b/src/lib/stepper/_stepper-theme.scss index 4f72d6ab0f48..d61eb4715996 100644 --- a/src/lib/stepper/_stepper-theme.scss +++ b/src/lib/stepper/_stepper-theme.scss @@ -9,6 +9,11 @@ .mat-horizontal-stepper-header, .mat-vertical-stepper-header { + &:focus, + &:hover { + background-color: mat-color($background, hover); + } + .mat-stepper-label { color: mat-color($foreground, text); } @@ -33,11 +38,11 @@ background-color: mat-color($background, card); } - .mat-vertical-content-container { + .mat-stepper-vertical-line::before { border-left-color: mat-color($foreground, divider); } - .mat-connector-line { + .mat-stepper-horizontal-line { border-top-color: mat-color($foreground, divider); } } diff --git a/src/lib/stepper/stepper-horizontal.html b/src/lib/stepper/stepper-horizontal.html index 0eade60c9f35..6472a981ff9b 100644 --- a/src/lib/stepper/stepper-horizontal.html +++ b/src/lib/stepper/stepper-horizontal.html @@ -21,7 +21,7 @@ -
+
diff --git a/src/lib/stepper/stepper-vertical.html b/src/lib/stepper/stepper-vertical.html index 8efe7a283932..99dc3a6ac1c1 100644 --- a/src/lib/stepper/stepper-vertical.html +++ b/src/lib/stepper/stepper-vertical.html @@ -19,7 +19,7 @@
-
+
{ let stepHeaders = fixture.debugElement.queryAll(By.css('.mat-horizontal-stepper-header')); checkKeyboardEvent(stepperComponent, fixture, stepHeaders); }); + + it('should not set focus on header of selected step if header is not clicked', () => { + let stepHeaderEl = fixture.debugElement + .queryAll(By.css('.mat-horizontal-stepper-header'))[1].nativeElement; + checkStepHeaderFocusNotCalled(stepHeaderEl, stepperComponent, fixture); + }); }); describe('linear horizontal stepper', () => { @@ -105,6 +111,12 @@ describe('MdHorizontalStepper', () => { .queryAll(By.css('.mat-horizontal-stepper-header'))[1].nativeElement; checkLinearStepperValidity(stepHeaderEl, stepperComponent, testComponent, fixture); }); + + it('should not focus step header upon click if it is not able to be selected', () => { + let stepHeaderEl = fixture.debugElement + .queryAll(By.css('.mat-horizontal-stepper-header'))[1].nativeElement; + checkStepHeaderBlur(stepHeaderEl, fixture); + }); }); }); @@ -173,6 +185,12 @@ describe('MdVerticalStepper', () => { let stepHeaders = fixture.debugElement.queryAll(By.css('.mat-vertical-stepper-header')); checkKeyboardEvent(stepperComponent, fixture, stepHeaders); }); + + it('should not set focus on header of selected step if header is not clicked', () => { + let stepHeaderEl = fixture.debugElement + .queryAll(By.css('.mat-vertical-stepper-header'))[1].nativeElement; + checkStepHeaderFocusNotCalled(stepHeaderEl, stepperComponent, fixture); + }); }); describe('linear vertical stepper', () => { @@ -204,6 +222,12 @@ describe('MdVerticalStepper', () => { checkLinearStepperValidity(stepHeaderEl, stepperComponent, testComponent, fixture); }); + + it('should not focus step header upon click if it is not able to be selected', () => { + let stepHeaderEl = fixture.debugElement + .queryAll(By.css('.mat-vertical-stepper-header'))[1].nativeElement; + checkStepHeaderBlur(stepHeaderEl, fixture); + }); }); }); @@ -387,6 +411,19 @@ function checkKeyboardEvent(stepperComponent: MdStepper, 'Expected index of selected step to change to index of focused step after SPACE event.'); } +function checkStepHeaderFocusNotCalled(stepHeaderEl: HTMLElement, + stepperComponent: MdStepper, + fixture: ComponentFixture) { + let nextButtonNativeEl = fixture.debugElement + .queryAll(By.directive(MdStepperNext))[0].nativeElement; + spyOn(stepHeaderEl, 'focus'); + nextButtonNativeEl.click(); + fixture.detectChanges(); + + expect(stepperComponent.selectedIndex).toBe(1); + expect(stepHeaderEl.focus).not.toHaveBeenCalled(); +} + function checkLinearStepperValidity(stepHeaderEl: HTMLElement, stepperComponent: MdStepper, testComponent: @@ -412,6 +449,14 @@ function checkLinearStepperValidity(stepHeaderEl: HTMLElement, expect(stepperComponent.selectedIndex).toBe(1); } +function checkStepHeaderBlur(stepHeaderEl: HTMLElement, fixture: ComponentFixture) { + spyOn(stepHeaderEl, 'blur'); + stepHeaderEl.click(); + fixture.detectChanges(); + + expect(stepHeaderEl.blur).toHaveBeenCalled(); +} + @Component({ template: `