Skip to content

Commit cbe6e68

Browse files
committed
fix(material/stepper): remove invalid aria attribute
We have an `aria-expanded` attribute on the `tabpanel` which is invalid. See https://w3c.github.io/aria/#aria-expanded. Fixes #25637.
1 parent 4de4e66 commit cbe6e68

File tree

5 files changed

+6
-22
lines changed

5 files changed

+6
-22
lines changed

src/cdk/stepper/stepper.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ your own component, it is recommended that the stepper is treated as a tabbed vi
6363
purposes by giving it a `role="tablist"`. The header of step that can be clicked to select the step
6464
should be given `role="tab"`, and the content that can be expanded upon selection should be given
6565
`role="tabpanel"`. Furthermore, the step header should have an `aria-selected` attribute that
66-
reflects its selected state and the associated content element should have `aria-expanded`.
66+
reflects its selected state.
6767

6868
You can refer to the [Angular Material stepper](https://github.com/angular/components/tree/main/src/material/stepper) as an example of an accessible implementation.

src/material/stepper/stepper.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
(@horizontalStepTransition.done)="_animationDone.next($event)"
2121
[id]="_getStepContentId(i)"
2222
[attr.aria-labelledby]="_getStepLabelId(i)"
23-
[attr.aria-expanded]="selectedIndex === i">
23+
[class.mat-horizontal-stepper-content-inactive]="selectedIndex !== i">
2424
<ng-container [ngTemplateOutlet]="step.content"></ng-container>
2525
</div>
2626
</div>
@@ -41,7 +41,7 @@
4141
(@verticalStepTransition.done)="_animationDone.next($event)"
4242
[id]="_getStepContentId(i)"
4343
[attr.aria-labelledby]="_getStepLabelId(i)"
44-
[attr.aria-expanded]="selectedIndex === i">
44+
[class.mat-vertical-stepper-content-inactive]="selectedIndex !== i">
4545
<div class="mat-vertical-content">
4646
<ng-container [ngTemplateOutlet]="step.content"></ng-container>
4747
</div>

src/material/stepper/stepper.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ export class MyApp {}
231231
The stepper is treated as a tabbed view for accessibility purposes, so it is given
232232
`role="tablist"` by default. The header of step that can be clicked to select the step
233233
is given `role="tab"`, and the content that can be expanded upon selection is given
234-
`role="tabpanel"`. `aria-selected` attribute of step header and `aria-expanded` attribute of
235-
step content is automatically set based on step selection change.
234+
`role="tabpanel"`. `aria-selected` attribute of step header is automatically set based on
235+
step selection change.
236236

237237
The stepper and each step should be given a meaningful label via `aria-label` or `aria-labelledby`.
238238

src/material/stepper/stepper.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
.mat-horizontal-stepper-content {
130130
outline: 0;
131131

132-
&[aria-expanded='false'] {
132+
&.mat-horizontal-stepper-content-inactive {
133133
height: 0;
134134
overflow: hidden;
135135
}

src/material/stepper/stepper.spec.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,6 @@ describe('MatStepper', () => {
131131
expect(stepperEl.getAttribute('role')).toBe('tablist');
132132
});
133133

134-
it('should set aria-expanded of content correctly', () => {
135-
const stepContents = fixture.debugElement.queryAll(By.css(`.mat-vertical-stepper-content`));
136-
const stepperComponent = fixture.debugElement.query(
137-
By.directive(MatStepper),
138-
)!.componentInstance;
139-
const firstStepContentEl = stepContents[0].nativeElement;
140-
expect(firstStepContentEl.getAttribute('aria-expanded')).toBe('true');
141-
142-
stepperComponent.selectedIndex = 1;
143-
fixture.detectChanges();
144-
145-
expect(firstStepContentEl.getAttribute('aria-expanded')).toBe('false');
146-
const secondStepContentEl = stepContents[1].nativeElement;
147-
expect(secondStepContentEl.getAttribute('aria-expanded')).toBe('true');
148-
});
149-
150134
it('should display the correct label', () => {
151135
const stepperComponent = fixture.debugElement.query(
152136
By.directive(MatStepper),

0 commit comments

Comments
 (0)