Skip to content

fix(material/stepper): add text for screen readers to indicate when step is complete #23519

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
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
2 changes: 2 additions & 0 deletions src/material/stepper/step-header.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
[ngTemplateOutletContext]="_getIconContext()"></ng-container>
<ng-container *ngSwitchDefault [ngSwitch]="state">
<span *ngSwitchCase="'number'">{{_getDefaultTextForState(state)}}</span>
<span class="cdk-visually-hidden" *ngIf="state === 'done'">{{_intl.completedLabel}}</span>
<span class="cdk-visually-hidden" *ngIf="state === 'edit'">{{_intl.editableLabel}}</span>
<mat-icon *ngSwitchDefault>{{_getDefaultTextForState(state)}}</mat-icon>
</ng-container>
</div>
Expand Down
6 changes: 6 additions & 0 deletions src/material/stepper/stepper-intl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export class MatStepperIntl {

/** Label that is rendered below optional steps. */
optionalLabel: string = 'Optional';

/** Label that is used to indicate step as completed to screen readers. */
completedLabel: string = 'Completed';

/** Label that is used to indicate step as editable to screen readers. */
editableLabel: string = 'Editable';
}


Expand Down
62 changes: 62 additions & 0 deletions src/material/stepper/stepper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,68 @@ describe('MatStepper', () => {
}));
});

describe('basic stepper with completed label change', () => {
let fixture: ComponentFixture<SimpleMatHorizontalStepperApp>;

beforeEach(() => {
fixture = createComponent(SimpleMatHorizontalStepperApp);
fixture.detectChanges();
});

it('should re-render when the completed labels change', inject([MatStepperIntl],
(intl: MatStepperIntl) => {
const stepperDebugElement = fixture.debugElement.query(By.directive(MatStepper))!;
const stepperComponent: MatStepper = stepperDebugElement.componentInstance;

stepperComponent.steps.toArray()[0].editable = false;
stepperComponent.next();
fixture.detectChanges();

const header = stepperDebugElement.nativeElement.querySelector('mat-step-header');
const completedLabel = header.querySelector('.cdk-visually-hidden');

expect(completedLabel).toBeTruthy();
expect(completedLabel.textContent).toBe('Completed');

intl.completedLabel = 'Completada';
intl.changes.next();
fixture.detectChanges();

expect(completedLabel.textContent).toBe('Completada');
}));
});

describe('basic stepper with editable label change', () => {
let fixture: ComponentFixture<SimpleMatHorizontalStepperApp>;

beforeEach(() => {
fixture = createComponent(SimpleMatHorizontalStepperApp);
fixture.detectChanges();
});

it('should re-render when the editable label changes', inject([MatStepperIntl],
(intl: MatStepperIntl) => {
const stepperDebugElement = fixture.debugElement.query(By.directive(MatStepper))!;
const stepperComponent: MatStepper = stepperDebugElement.componentInstance;

stepperComponent.steps.toArray()[0].editable = true;
stepperComponent.next();
fixture.detectChanges();

const header = stepperDebugElement.nativeElement.querySelector('mat-step-header');
const editableLabel = header.querySelector('.cdk-visually-hidden');

expect(editableLabel).toBeTruthy();
expect(editableLabel.textContent).toBe('Editable');

intl.editableLabel = 'Modificabile';
intl.changes.next();
fixture.detectChanges();

expect(editableLabel.textContent).toBe('Modificabile');
}));
});

describe('icon overrides', () => {
let fixture: ComponentFixture<IconOverridesStepper>;

Expand Down
2 changes: 2 additions & 0 deletions tools/public_api_guard/material/stepper.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ export interface MatStepperIconContext {
// @public
export class MatStepperIntl {
readonly changes: Subject<void>;
completedLabel: string;
editableLabel: string;
optionalLabel: string;
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<MatStepperIntl, never>;
Expand Down