Skip to content

Commit f259e4f

Browse files
committed
refactor(material/stepper): cleans up unnecessary roles/attributes
Updates previous fix to Angular Components stepper to remove unnecessary roles and attributes. Also updates Stepper docs with latest vertical stepper aria attribute and role changes. Updates stepper-demo heading level elements for accessibility purposes.
1 parent 49c1419 commit f259e4f

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/dev-app/stepper/stepper-demo.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<h1>Stepper Demo</h1>
12
<p>
23
<mat-checkbox [(ngModel)]="isNonLinear">Disable linear mode</mat-checkbox>
34
</p>
@@ -23,7 +24,7 @@
2324
</mat-form-field>
2425
</p>
2526

26-
<h3>Linear Stepper Demo using a single form</h3>
27+
<h2>Linear Stepper Demo using a single form</h2>
2728
<form [formGroup]="formGroup">
2829
<mat-stepper
2930
#linearStepper="matVerticalStepper"
@@ -77,7 +78,7 @@ <h3>Linear Stepper Demo using a single form</h3>
7778
</mat-stepper>
7879
</form>
7980

80-
<h3>Linear Horizontal Stepper Demo using a different form for each step</h3>
81+
<h2>Linear Horizontal Stepper Demo using a different form for each step</h2>
8182
<mat-stepper #linearHorizontalStepper="matHorizontalStepper" [linear]="!isNonLinear"
8283
[disableRipple]="disableRipple"
8384
[labelPosition]="showLabelBottom ? 'bottom' : 'end'"
@@ -128,7 +129,7 @@ <h3>Linear Horizontal Stepper Demo using a different form for each step</h3>
128129
</mat-step>
129130
</mat-stepper>
130131

131-
<h3>Vertical Stepper Demo</h3>
132+
<h2>Vertical Stepper Demo</h2>
132133
<mat-checkbox [(ngModel)]="isNonEditable">Make steps non-editable</mat-checkbox>
133134
<mat-stepper orientation="vertical" [color]="theme">
134135
<mat-step [editable]="!isNonEditable">
@@ -184,7 +185,7 @@ <h3>Vertical Stepper Demo</h3>
184185
</mat-step>
185186
</mat-stepper>
186187

187-
<h3>Horizontal Stepper Demo with Text Label</h3>
188+
<h2>Horizontal Stepper Demo with Text Label</h2>
188189
<mat-stepper [color]="theme">
189190
<mat-step label="Fill out your name">
190191
<mat-form-field>
@@ -231,7 +232,7 @@ <h3>Horizontal Stepper Demo with Text Label</h3>
231232
</mat-step>
232233
</mat-stepper>
233234

234-
<h3>Horizontal Stepper Demo with Templated Label</h3>
235+
<h2>Horizontal Stepper Demo with Templated Label</h2>
235236
<mat-stepper [color]="theme">
236237
@for (step of steps; track step) {
237238
<mat-step>
@@ -248,7 +249,7 @@ <h3>Horizontal Stepper Demo with Templated Label</h3>
248249
}
249250
</mat-stepper>
250251

251-
<h3>Stepper with autosize textarea</h3>
252+
<h2>Stepper with autosize textarea</h2>
252253
<mat-stepper [color]="theme">
253254
<mat-step label="Step 1">
254255
<mat-form-field>

src/material/stepper/stepper.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,11 @@
8585
(keydown)="_onKeydown($event)"
8686
[tabIndex]="_getFocusIndex() === i ? 0 : -1"
8787
[id]="_getStepLabelId(i)"
88-
[attr.role]="orientation === 'horizontal'? 'tab' : 'heading'"
88+
[attr.role]="orientation === 'horizontal'? 'tab' : undefined"
8989
[attr.aria-posinset]="orientation === 'horizontal'? i + 1 : undefined"
9090
[attr.aria-setsize]="orientation === 'horizontal'? steps.length : undefined"
9191
[attr.aria-controls]="orientation === 'horizontal'? _getStepContentId(i) : undefined"
9292
[attr.aria-selected]="orientation === 'horizontal'? selectedIndex == i : undefined"
93-
[attr.aria-level]="orientation === 'vertical'? 4 : undefined"
9493
[attr.aria-label]="step.ariaLabel || null"
9594
[attr.aria-labelledby]="(!step.ariaLabel && step.ariaLabelledby) ? step.ariaLabelledby : null"
9695
[attr.aria-disabled]="orientation === 'horizontal'? _stepIsNavigable(i, step) ? null : true : undefined"

src/material/stepper/stepper.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,17 @@ export class MyApp {}
228228
<!-- example(stepper-intl) -->
229229

230230
### Accessibility
231-
The stepper is treated as a tabbed view for accessibility purposes, so it is given
232-
`role="tablist"` by default. The header of step that can be clicked to select the step
231+
The stepper is treated as a tabbed view for accessibility purposes.
232+
233+
For a horizontal stepper, based on its structure it is given `role="tablist"` by default. The header of step that can be clicked to select the step
233234
is given `role="tab"`, and the content that can be expanded upon selection is given
234235
`role="tabpanel"`. `aria-selected` attribute of step header is automatically set based on
235236
step selection change.
236237

238+
For a vertical stepper, based on its structure it is given `role="tree"` by default. The `.mat-step` of each vertical step that can be clicked to select the step
239+
is given `role="treeitem"`, and the `.mat-step` gets an `aria-selected` and `aria-expanded` attribute of the `tree-item` is automatically set based on
240+
step selection change.
241+
237242
The stepper and each step should be given a meaningful label via `aria-label` or `aria-labelledby`.
238243

239244
Prefer vertical steppers when building for small screen sizes, as horizontal

0 commit comments

Comments
 (0)