Skip to content

Commit 9a77164

Browse files
crisbetojosephperrott
authored andcommitted
fix(stepper): unable to tab to step content (#14892)
Along the same line as #14808. Fixes not being able to reach the content of a step if it doesn't have focusable content already. Based on the [tabs example from the accessibility guidelines](https://www.w3.org/TR/wai-aria-practices-1.1/examples/tabs/tabs-2/tabs.html).
1 parent 679bdb6 commit 9a77164

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

src/lib/stepper/stepper-horizontal.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
<div class="mat-horizontal-content-container">
2929
<div *ngFor="let step of steps; let i = index"
30+
[attr.tabindex]="selectedIndex === i ? 0 : null"
3031
class="mat-horizontal-stepper-content" role="tabpanel"
3132
[@stepTransition]="_getAnimationDirection(i)"
3233
(@stepTransition.done)="_animationDone.next($event)"

src/lib/stepper/stepper-vertical.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
<div class="mat-vertical-content-container" [class.mat-stepper-vertical-line]="!isLast">
2525
<div class="mat-vertical-stepper-content" role="tabpanel"
26+
[attr.tabindex]="selectedIndex === i ? 0 : null"
2627
[@stepTransition]="_getAnimationDirection(i)"
2728
(@stepTransition.done)="_animationDone.next($event)"
2829
[id]="_getStepContentId(i)"

src/lib/stepper/stepper.scss

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,13 @@ $mat-stepper-line-gap: 8px !default;
124124
}
125125
}
126126

127-
.mat-horizontal-stepper-content[aria-expanded='false'] {
128-
height: 0;
129-
overflow: hidden;
127+
.mat-horizontal-stepper-content {
128+
outline: 0;
129+
130+
&[aria-expanded='false'] {
131+
height: 0;
132+
overflow: hidden;
133+
}
130134
}
131135

132136
.mat-horizontal-content-container {
@@ -162,6 +166,7 @@ $mat-stepper-line-gap: 8px !default;
162166

163167
.mat-vertical-stepper-content {
164168
overflow: hidden;
169+
outline: 0;
165170
}
166171

167172
.mat-vertical-content {

src/lib/stepper/stepper.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,23 @@ describe('MatStepper', () => {
361361
const stepHeaders = fixture.debugElement.queryAll(By.css('.mat-vertical-stepper-header'));
362362
assertSelectKeyWithModifierInteraction(fixture, stepHeaders, 'vertical', SPACE);
363363
});
364+
365+
it('should set the proper tabindex', () => {
366+
let stepContents = fixture.debugElement.queryAll(By.css(`.mat-vertical-stepper-content`));
367+
let stepperComponent = fixture.debugElement.query(By.directive(MatStepper)).componentInstance;
368+
let firstStepContentEl = stepContents[0].nativeElement;
369+
let secondStepContentEl = stepContents[1].nativeElement;
370+
371+
expect(firstStepContentEl.getAttribute('tabindex')).toBe('0');
372+
expect(secondStepContentEl.getAttribute('tabindex')).toBeFalsy();
373+
374+
stepperComponent.selectedIndex = 1;
375+
fixture.detectChanges();
376+
377+
expect(firstStepContentEl.getAttribute('tabindex')).toBeFalsy();
378+
expect(secondStepContentEl.getAttribute('tabindex')).toBe('0');
379+
});
380+
364381
});
365382

366383
describe('basic stepper when attempting to set the selected step too early', () => {

0 commit comments

Comments
 (0)