Skip to content

Commit 653f412

Browse files
authored
fix(material/stepper): indicate to assistive technology when step is 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.
1 parent c571da6 commit 653f412

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

src/material/stepper/stepper.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@
6161
[attr.aria-selected]="selectedIndex == i"
6262
[attr.aria-label]="step.ariaLabel || null"
6363
[attr.aria-labelledby]="(!step.ariaLabel && step.ariaLabelledby) ? step.ariaLabelledby : null"
64+
[attr.aria-disabled]="_stepIsNavigable(i, step) ? null : true"
6465
[index]="i"
6566
[state]="_getIndicatorType(i, step.state)"
6667
[label]="step.stepLabel || step.label"
6768
[selected]="selectedIndex === i"
68-
[active]="step.completed || selectedIndex === i || !linear"
69+
[active]="_stepIsNavigable(i, step)"
6970
[optional]="step.optional"
7071
[errorMessage]="step.errorMessage"
7172
[iconOverrides]="_iconOverrides"

src/material/stepper/stepper.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,15 @@ describe('MatStepper', () => {
789789
expect(testComponent.oneGroup.valid).toBe(false);
790790
expect(stepperComponent.selectedIndex).toBe(1);
791791
});
792+
793+
it('should set aria-disabled if the user is not able to navigate to a step', () => {
794+
const stepHeaders = Array.from<HTMLElement>(
795+
fixture.nativeElement.querySelectorAll('.mat-vertical-stepper-header'));
796+
797+
expect(stepHeaders.map(step => step.getAttribute('aria-disabled')))
798+
.toEqual([null, 'true', 'true', 'true']);
799+
});
800+
792801
});
793802

794803
describe('linear stepper with a pre-defined selectedIndex', () => {

src/material/stepper/stepper.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,8 @@ export class MatStepper extends CdkStepper implements AfterContentInit {
239239
}
240240
});
241241
}
242+
243+
_stepIsNavigable(index: number, step: MatStep): boolean {
244+
return step.completed || this.selectedIndex === index || !this.linear;
245+
}
242246
}

tools/public_api_guard/material/stepper.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export declare class MatStepper extends CdkStepper implements AfterContentInit {
7474
labelPosition: 'bottom' | 'end';
7575
readonly steps: QueryList<MatStep>;
7676
constructor(dir: Directionality, changeDetectorRef: ChangeDetectorRef, elementRef: ElementRef<HTMLElement>, _document: any);
77+
_stepIsNavigable(index: number, step: MatStep): boolean;
7778
ngAfterContentInit(): void;
7879
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>;
7980
static ɵfac: i0.ɵɵFactoryDeclaration<MatStepper, [{ optional: true; }, null, null, null]>;

0 commit comments

Comments
 (0)