Skip to content

Commit

Permalink
fix(material/stepper): indicate to assistive technology when step is …
Browse files Browse the repository at this point in the history
…disabled (#23090)

Currently the stepper has no non-visual indication of whether a step is disabled. This is confusing, because selecting it won't do anything.

Fixes #23088.

(cherry picked from commit 653f412)
  • Loading branch information
crisbeto authored and andrewseguin committed Jul 2, 2021
1 parent e688744 commit 6a794ab
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/material/stepper/stepper.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@
[attr.aria-selected]="selectedIndex == i"
[attr.aria-label]="step.ariaLabel || null"
[attr.aria-labelledby]="(!step.ariaLabel && step.ariaLabelledby) ? step.ariaLabelledby : null"
[attr.aria-disabled]="_stepIsNavigable(i, step) ? null : true"
[index]="i"
[state]="_getIndicatorType(i, step.state)"
[label]="step.stepLabel || step.label"
[selected]="selectedIndex === i"
[active]="step.completed || selectedIndex === i || !linear"
[active]="_stepIsNavigable(i, step)"
[optional]="step.optional"
[errorMessage]="step.errorMessage"
[iconOverrides]="_iconOverrides"
Expand Down
9 changes: 9 additions & 0 deletions src/material/stepper/stepper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,15 @@ describe('MatStepper', () => {
expect(testComponent.oneGroup.valid).toBe(false);
expect(stepperComponent.selectedIndex).toBe(1);
});

it('should set aria-disabled if the user is not able to navigate to a step', () => {
const stepHeaders = Array.from<HTMLElement>(
fixture.nativeElement.querySelectorAll('.mat-vertical-stepper-header'));

expect(stepHeaders.map(step => step.getAttribute('aria-disabled')))
.toEqual([null, 'true', 'true', 'true']);
});

});

describe('linear stepper with a pre-defined selectedIndex', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/material/stepper/stepper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,8 @@ export class MatStepper extends CdkStepper implements AfterContentInit {
}
});
}

_stepIsNavigable(index: number, step: MatStep): boolean {
return step.completed || this.selectedIndex === index || !this.linear;
}
}
1 change: 1 addition & 0 deletions tools/public_api_guard/material/stepper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export declare class MatStepper extends CdkStepper implements AfterContentInit {
labelPosition: 'bottom' | 'end';
readonly steps: QueryList<MatStep>;
constructor(dir: Directionality, changeDetectorRef: ChangeDetectorRef, elementRef: ElementRef<HTMLElement>, _document: any);
_stepIsNavigable(index: number, step: MatStep): boolean;
ngAfterContentInit(): void;
static ɵcmp: i0.ɵɵComponentDeclaration<MatStepper, "mat-stepper, mat-vertical-stepper, mat-horizontal-stepper, [matStepper]", ["matStepper", "matVerticalStepper", "matHorizontalStepper"], { "selectedIndex": "selectedIndex"; "disableRipple": "disableRipple"; "color": "color"; "labelPosition": "labelPosition"; }, { "animationDone": "animationDone"; }, ["_steps", "_icons"], never>;
static ɵfac: i0.ɵɵFactoryDeclaration<MatStepper, [{ optional: true; }, null, null, null]>;
Expand Down

0 comments on commit 6a794ab

Please sign in to comment.