Skip to content

Commit 9056d95

Browse files
amysortommalerba
authored andcommitted
fix(material/stepper): add text for screen readers to indicate when step is complete or editable (#23519)
(cherry picked from commit 2602d2e)
1 parent 544423b commit 9056d95

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

src/material/stepper/step-header.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
[ngTemplateOutletContext]="_getIconContext()"></ng-container>
1111
<ng-container *ngSwitchDefault [ngSwitch]="state">
1212
<span *ngSwitchCase="'number'">{{_getDefaultTextForState(state)}}</span>
13+
<span class="cdk-visually-hidden" *ngIf="state === 'done'">{{_intl.completedLabel}}</span>
14+
<span class="cdk-visually-hidden" *ngIf="state === 'edit'">{{_intl.editableLabel}}</span>
1315
<mat-icon *ngSwitchDefault>{{_getDefaultTextForState(state)}}</mat-icon>
1416
</ng-container>
1517
</div>

src/material/stepper/stepper-intl.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ export class MatStepperIntl {
2121

2222
/** Label that is rendered below optional steps. */
2323
optionalLabel: string = 'Optional';
24+
25+
/** Label that is used to indicate step as completed to screen readers. */
26+
completedLabel: string = 'Completed';
27+
28+
/** Label that is used to indicate step as editable to screen readers. */
29+
editableLabel: string = 'Editable';
2430
}
2531

2632

src/material/stepper/stepper.spec.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,68 @@ describe('MatStepper', () => {
476476
}));
477477
});
478478

479+
describe('basic stepper with completed label change', () => {
480+
let fixture: ComponentFixture<SimpleMatHorizontalStepperApp>;
481+
482+
beforeEach(() => {
483+
fixture = createComponent(SimpleMatHorizontalStepperApp);
484+
fixture.detectChanges();
485+
});
486+
487+
it('should re-render when the completed labels change', inject([MatStepperIntl],
488+
(intl: MatStepperIntl) => {
489+
const stepperDebugElement = fixture.debugElement.query(By.directive(MatStepper))!;
490+
const stepperComponent: MatStepper = stepperDebugElement.componentInstance;
491+
492+
stepperComponent.steps.toArray()[0].editable = false;
493+
stepperComponent.next();
494+
fixture.detectChanges();
495+
496+
const header = stepperDebugElement.nativeElement.querySelector('mat-step-header');
497+
const completedLabel = header.querySelector('.cdk-visually-hidden');
498+
499+
expect(completedLabel).toBeTruthy();
500+
expect(completedLabel.textContent).toBe('Completed');
501+
502+
intl.completedLabel = 'Completada';
503+
intl.changes.next();
504+
fixture.detectChanges();
505+
506+
expect(completedLabel.textContent).toBe('Completada');
507+
}));
508+
});
509+
510+
describe('basic stepper with editable label change', () => {
511+
let fixture: ComponentFixture<SimpleMatHorizontalStepperApp>;
512+
513+
beforeEach(() => {
514+
fixture = createComponent(SimpleMatHorizontalStepperApp);
515+
fixture.detectChanges();
516+
});
517+
518+
it('should re-render when the editable label changes', inject([MatStepperIntl],
519+
(intl: MatStepperIntl) => {
520+
const stepperDebugElement = fixture.debugElement.query(By.directive(MatStepper))!;
521+
const stepperComponent: MatStepper = stepperDebugElement.componentInstance;
522+
523+
stepperComponent.steps.toArray()[0].editable = true;
524+
stepperComponent.next();
525+
fixture.detectChanges();
526+
527+
const header = stepperDebugElement.nativeElement.querySelector('mat-step-header');
528+
const editableLabel = header.querySelector('.cdk-visually-hidden');
529+
530+
expect(editableLabel).toBeTruthy();
531+
expect(editableLabel.textContent).toBe('Editable');
532+
533+
intl.editableLabel = 'Modificabile';
534+
intl.changes.next();
535+
fixture.detectChanges();
536+
537+
expect(editableLabel.textContent).toBe('Modificabile');
538+
}));
539+
});
540+
479541
describe('icon overrides', () => {
480542
let fixture: ComponentFixture<IconOverridesStepper>;
481543

tools/public_api_guard/material/stepper.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ export interface MatStepperIconContext {
184184
// @public
185185
export class MatStepperIntl {
186186
readonly changes: Subject<void>;
187+
completedLabel: string;
188+
editableLabel: string;
187189
optionalLabel: string;
188190
// (undocumented)
189191
static ɵfac: i0.ɵɵFactoryDeclaration<MatStepperIntl, never>;

0 commit comments

Comments
 (0)