Skip to content

fix(material/stepper): generalize stepper aria roles #31256

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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: 1 addition & 1 deletion src/cdk/stepper/step-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {FocusableOption} from '../a11y';
@Directive({
selector: '[cdkStepHeader]',
host: {
'role': 'tab',
'role': 'button',
},
})
export class CdkStepHeader implements FocusableOption {
Expand Down
2 changes: 1 addition & 1 deletion src/material/stepper/step-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {_CdkPrivateStyleLoader, _VisuallyHiddenLoader} from '@angular/cdk/privat
host: {
'class': 'mat-step-header',
'[class]': '"mat-" + (color || "primary")',
'role': 'tab',
'role': 'button',
},
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
Expand Down
52 changes: 28 additions & 24 deletions src/material/stepper/stepper.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@switch (orientation) {
@case ('horizontal') {
<div class="mat-horizontal-stepper-wrapper">
<div class="mat-horizontal-stepper-wrapper" role="group">
<div class="mat-horizontal-stepper-header-container">
@for (step of steps; track step) {
<ng-container
Expand All @@ -27,7 +27,7 @@
<div
#animatedContainer
class="mat-horizontal-stepper-content"
role="tabpanel"
role="region"
[id]="_getStepContentId($index)"
[attr.aria-labelledby]="_getStepLabelId($index)"
[class]="'mat-horizontal-stepper-content-' + _getAnimationDirection($index)"
Expand All @@ -40,28 +40,30 @@
}

@case ('vertical') {
@for (step of steps; track step) {
<div class="mat-step">
<ng-container
[ngTemplateOutlet]="stepTemplate"
[ngTemplateOutletContext]="{step}"/>
<div
#animatedContainer
class="mat-vertical-content-container"
[class.mat-stepper-vertical-line]="!$last"
[class.mat-vertical-content-container-active]="selectedIndex === $index"
[attr.inert]="selectedIndex === $index ? null : ''">
<div class="mat-vertical-stepper-content"
role="tabpanel"
[id]="_getStepContentId($index)"
[attr.aria-labelledby]="_getStepLabelId($index)">
<div class="mat-vertical-content">
<ng-container [ngTemplateOutlet]="step.content"/>
<div class="mat-vertical-stepper-wrapper" role="group">
@for (step of steps; track step) {
<div class="mat-step">
<ng-container
[ngTemplateOutlet]="stepTemplate"
[ngTemplateOutletContext]="{step}"/>
<div
#animatedContainer
class="mat-vertical-content-container"
[class.mat-stepper-vertical-line]="!$last"
[class.mat-vertical-content-container-active]="selectedIndex === $index"
[attr.inert]="selectedIndex === $index ? null : ''">
<div class="mat-vertical-stepper-content"
role="region"
[id]="_getStepContentId($index)"
[attr.aria-labelledby]="_getStepLabelId($index)">
<div class="mat-vertical-content">
<ng-container [ngTemplateOutlet]="step.content"/>
</div>
</div>
</div>
</div>
</div>
}
}
</div>
}
}

Expand All @@ -74,13 +76,15 @@
(keydown)="_onKeydown($event)"
[tabIndex]="_getFocusIndex() === step.index() ? 0 : -1"
[id]="_getStepLabelId(step.index())"
[attr.aria-posinset]="step.index() + 1"
[attr.aria-setsize]="steps.length"
[attr.aria-controls]="_getStepContentId(step.index())"
[attr.aria-selected]="step.isSelected()"
[attr.aria-expanded]="orientation === 'vertical' ? step.isSelected() : undefined"
[attr.aria-current]="step.isSelected() ? 'step' : undefined"
[attr.aria-pressed]="step.isSelected()"
[attr.aria-label]="step.ariaLabel || null"
[attr.aria-labelledby]="(!step.ariaLabel && step.ariaLabelledby) ? step.ariaLabelledby : null"
[attr.aria-disabled]="step.isNavigable() ? null : true"
[attr.aria-owns]="_getStepContentId(step.index())"
[attr.mat-step-index]="step.index()"
[index]="step.index()"
[state]="step.indicatorType()"
[label]="step.stepLabel || step.label"
Expand Down
1 change: 0 additions & 1 deletion src/material/stepper/stepper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export class MatStep extends CdkStep implements ErrorStateMatcher, AfterContentI
'[class.mat-stepper-animating]': '_isAnimating()',
'[style.--mat-stepper-animation-duration]': '_getAnimationDuration()',
'[attr.aria-orientation]': 'orientation',
'role': 'tablist',
},
providers: [{provide: CdkStepper, useExisting: MatStepper}],
encapsulation: ViewEncapsulation.None,
Expand Down
Loading