Skip to content

Commit 824aad2

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 4aa5535 commit 824aad2

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
@@ -26,6 +26,7 @@
2626

2727
<div class="mat-horizontal-content-container">
2828
<div *ngFor="let step of steps; let i = index"
29+
[attr.tabindex]="selectedIndex === i ? 0 : null"
2930
class="mat-horizontal-stepper-content" role="tabpanel"
3031
[@stepTransition]="_getAnimationDirection(i)"
3132
(@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
@@ -22,6 +22,7 @@
2222

2323
<div class="mat-vertical-content-container" [class.mat-stepper-vertical-line]="!isLast">
2424
<div class="mat-vertical-stepper-content" role="tabpanel"
25+
[attr.tabindex]="selectedIndex === i ? 0 : null"
2526
[@stepTransition]="_getAnimationDirection(i)"
2627
(@stepTransition.done)="_animationDone.next($event)"
2728
[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
@@ -360,6 +360,23 @@ describe('MatStepper', () => {
360360
const stepHeaders = fixture.debugElement.queryAll(By.css('.mat-vertical-stepper-header'));
361361
assertSelectKeyWithModifierInteraction(fixture, stepHeaders, 'vertical', SPACE);
362362
});
363+
364+
it('should set the proper tabindex', () => {
365+
let stepContents = fixture.debugElement.queryAll(By.css(`.mat-vertical-stepper-content`));
366+
let stepperComponent = fixture.debugElement.query(By.directive(MatStepper)).componentInstance;
367+
let firstStepContentEl = stepContents[0].nativeElement;
368+
let secondStepContentEl = stepContents[1].nativeElement;
369+
370+
expect(firstStepContentEl.getAttribute('tabindex')).toBe('0');
371+
expect(secondStepContentEl.getAttribute('tabindex')).toBeFalsy();
372+
373+
stepperComponent.selectedIndex = 1;
374+
fixture.detectChanges();
375+
376+
expect(firstStepContentEl.getAttribute('tabindex')).toBeFalsy();
377+
expect(secondStepContentEl.getAttribute('tabindex')).toBe('0');
378+
});
379+
363380
});
364381

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

0 commit comments

Comments
 (0)