Skip to content

fix(material/stepper): indicate to assistive technology when step is disabled #23090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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