Skip to content

Commit c1a6f5e

Browse files
authored
make the progress bar accessible as breadcrumbs (#67)
* make the progress bar accessible as breadcrumbs * update snapshots
1 parent e2a52e2 commit c1a6f5e

File tree

2 files changed

+69
-17
lines changed

2 files changed

+69
-17
lines changed

src/components/ProgressBar.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
55
import { faCheck } from '@fortawesome/free-solid-svg-icons/faCheck';
66
import { faXmark } from '@fortawesome/free-solid-svg-icons/faXmark';
77

8-
const ProgressBarWrapper = styled.div`
8+
const ProgressBarWrapper = styled.nav`
99
display: flex;
1010
justify-content: flex-start;
1111
flex-wrap: wrap;
@@ -131,18 +131,25 @@ export type ProgressBarItemVariant = 'isCorrect' | 'isIncorrect' | 'isStatus' |
131131

132132
export const ProgressBarItem = <S extends {variant: ProgressBarItemVariant}>({index, isActive, step, goToStep}: ProgressBarItemProps<S>) =>
133133
<StyledItemWrapper>
134-
<StyledItem variant={step.variant} isActive={isActive} onClick={() => goToStep(index, step)}>
134+
<StyledItem
135+
variant={step.variant}
136+
isActive={isActive}
137+
onClick={() => goToStep(index, step)}
138+
aria-current={isActive ? 'location' : 'false'}
139+
aria-label={step.variant === 'isStatus' ? 'Assignment status' : `Step ${index + 1}` }
140+
>
135141
{step.variant === 'isStatus' ? <FlagIcon /> : index + 1}
136142
</StyledItem>
137143
<ItemIcon variant={step.variant} />
138144
</StyledItemWrapper>;
139145

140-
export const ProgressBar = <S extends {variant: ProgressBarItemVariant}>({ steps, activeIndex, goToStep }: ProgressBarProps<S>) => <ProgressBarWrapper>
141-
{steps.map((step, index) => <ProgressBarItem
142-
key={index}
143-
index={index}
144-
isActive={index === activeIndex}
145-
step={step}
146-
goToStep={goToStep}
147-
/>)}
148-
</ProgressBarWrapper>;
146+
export const ProgressBar = <S extends {variant: ProgressBarItemVariant}>({ steps, activeIndex, goToStep }: ProgressBarProps<S>) =>
147+
<ProgressBarWrapper aria-label="Breadcrumbs">
148+
{steps.map((step, index) => <ProgressBarItem
149+
key={index}
150+
index={index}
151+
isActive={index === activeIndex}
152+
step={step}
153+
goToStep={goToStep}
154+
/>)}
155+
</ProgressBarWrapper>;

src/components/__snapshots__/ProgressBar.spec.tsx.snap

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`ProgressBar matches snapshot 1`] = `
4-
<div
4+
<nav
5+
aria-label="Breadcrumbs"
56
className="sc-bczRLJ bQqPBP"
67
>
78
<span
89
className="sc-gsnTZi AyNuQ"
910
>
1011
<button
12+
aria-current="false"
13+
aria-label="Step 1"
1114
className="sc-dkzDqf KrxmS"
1215
onClick={[Function]}
1316
>
@@ -38,6 +41,8 @@ exports[`ProgressBar matches snapshot 1`] = `
3841
className="sc-gsnTZi AyNuQ"
3942
>
4043
<button
44+
aria-current="false"
45+
aria-label="Step 2"
4146
className="sc-dkzDqf gKblal"
4247
onClick={[Function]}
4348
>
@@ -68,6 +73,8 @@ exports[`ProgressBar matches snapshot 1`] = `
6873
className="sc-gsnTZi AyNuQ"
6974
>
7075
<button
76+
aria-current="location"
77+
aria-label="Step 3"
7178
className="sc-dkzDqf hmFFbY"
7279
onClick={[Function]}
7380
>
@@ -98,6 +105,8 @@ exports[`ProgressBar matches snapshot 1`] = `
98105
className="sc-gsnTZi AyNuQ"
99106
>
100107
<button
108+
aria-current="false"
109+
aria-label="Step 4"
101110
className="sc-dkzDqf iyRspZ"
102111
onClick={[Function]}
103112
>
@@ -108,6 +117,8 @@ exports[`ProgressBar matches snapshot 1`] = `
108117
className="sc-gsnTZi AyNuQ"
109118
>
110119
<button
120+
aria-current="false"
121+
aria-label="Step 5"
111122
className="sc-dkzDqf iyRspZ"
112123
onClick={[Function]}
113124
>
@@ -118,6 +129,8 @@ exports[`ProgressBar matches snapshot 1`] = `
118129
className="sc-gsnTZi AyNuQ"
119130
>
120131
<button
132+
aria-current="false"
133+
aria-label="Step 6"
121134
className="sc-dkzDqf iyRspZ"
122135
onClick={[Function]}
123136
>
@@ -128,6 +141,8 @@ exports[`ProgressBar matches snapshot 1`] = `
128141
className="sc-gsnTZi AyNuQ"
129142
>
130143
<button
144+
aria-current="false"
145+
aria-label="Assignment status"
131146
className="sc-dkzDqf iyRspZ"
132147
onClick={[Function]}
133148
>
@@ -145,17 +160,20 @@ exports[`ProgressBar matches snapshot 1`] = `
145160
</svg>
146161
</button>
147162
</span>
148-
</div>
163+
</nav>
149164
`;
150165

151166
exports[`ProgressBar matches snapshot when active step is incomplete 1`] = `
152-
<div
167+
<nav
168+
aria-label="Breadcrumbs"
153169
className="sc-bczRLJ bQqPBP"
154170
>
155171
<span
156172
className="sc-gsnTZi AyNuQ"
157173
>
158174
<button
175+
aria-current="false"
176+
aria-label="Step 1"
159177
className="sc-dkzDqf KrxmS"
160178
onClick={[Function]}
161179
>
@@ -186,6 +204,8 @@ exports[`ProgressBar matches snapshot when active step is incomplete 1`] = `
186204
className="sc-gsnTZi AyNuQ"
187205
>
188206
<button
207+
aria-current="false"
208+
aria-label="Step 2"
189209
className="sc-dkzDqf gKblal"
190210
onClick={[Function]}
191211
>
@@ -216,6 +236,8 @@ exports[`ProgressBar matches snapshot when active step is incomplete 1`] = `
216236
className="sc-gsnTZi AyNuQ"
217237
>
218238
<button
239+
aria-current="false"
240+
aria-label="Step 3"
219241
className="sc-dkzDqf KrxmS"
220242
onClick={[Function]}
221243
>
@@ -246,6 +268,8 @@ exports[`ProgressBar matches snapshot when active step is incomplete 1`] = `
246268
className="sc-gsnTZi AyNuQ"
247269
>
248270
<button
271+
aria-current="location"
272+
aria-label="Step 4"
249273
className="sc-dkzDqf ejGnvX"
250274
onClick={[Function]}
251275
>
@@ -256,6 +280,8 @@ exports[`ProgressBar matches snapshot when active step is incomplete 1`] = `
256280
className="sc-gsnTZi AyNuQ"
257281
>
258282
<button
283+
aria-current="false"
284+
aria-label="Step 5"
259285
className="sc-dkzDqf iyRspZ"
260286
onClick={[Function]}
261287
>
@@ -266,6 +292,8 @@ exports[`ProgressBar matches snapshot when active step is incomplete 1`] = `
266292
className="sc-gsnTZi AyNuQ"
267293
>
268294
<button
295+
aria-current="false"
296+
aria-label="Step 6"
269297
className="sc-dkzDqf iyRspZ"
270298
onClick={[Function]}
271299
>
@@ -276,6 +304,8 @@ exports[`ProgressBar matches snapshot when active step is incomplete 1`] = `
276304
className="sc-gsnTZi AyNuQ"
277305
>
278306
<button
307+
aria-current="false"
308+
aria-label="Assignment status"
279309
className="sc-dkzDqf iyRspZ"
280310
onClick={[Function]}
281311
>
@@ -293,17 +323,20 @@ exports[`ProgressBar matches snapshot when active step is incomplete 1`] = `
293323
</svg>
294324
</button>
295325
</span>
296-
</div>
326+
</nav>
297327
`;
298328

299329
exports[`ProgressBar matches snapshot when status step is active 1`] = `
300-
<div
330+
<nav
331+
aria-label="Breadcrumbs"
301332
className="sc-bczRLJ bQqPBP"
302333
>
303334
<span
304335
className="sc-gsnTZi AyNuQ"
305336
>
306337
<button
338+
aria-current="false"
339+
aria-label="Step 1"
307340
className="sc-dkzDqf KrxmS"
308341
onClick={[Function]}
309342
>
@@ -334,6 +367,8 @@ exports[`ProgressBar matches snapshot when status step is active 1`] = `
334367
className="sc-gsnTZi AyNuQ"
335368
>
336369
<button
370+
aria-current="false"
371+
aria-label="Step 2"
337372
className="sc-dkzDqf gKblal"
338373
onClick={[Function]}
339374
>
@@ -364,6 +399,8 @@ exports[`ProgressBar matches snapshot when status step is active 1`] = `
364399
className="sc-gsnTZi AyNuQ"
365400
>
366401
<button
402+
aria-current="false"
403+
aria-label="Step 3"
367404
className="sc-dkzDqf KrxmS"
368405
onClick={[Function]}
369406
>
@@ -394,6 +431,8 @@ exports[`ProgressBar matches snapshot when status step is active 1`] = `
394431
className="sc-gsnTZi AyNuQ"
395432
>
396433
<button
434+
aria-current="false"
435+
aria-label="Step 4"
397436
className="sc-dkzDqf iyRspZ"
398437
onClick={[Function]}
399438
>
@@ -404,6 +443,8 @@ exports[`ProgressBar matches snapshot when status step is active 1`] = `
404443
className="sc-gsnTZi AyNuQ"
405444
>
406445
<button
446+
aria-current="false"
447+
aria-label="Step 5"
407448
className="sc-dkzDqf iyRspZ"
408449
onClick={[Function]}
409450
>
@@ -414,6 +455,8 @@ exports[`ProgressBar matches snapshot when status step is active 1`] = `
414455
className="sc-gsnTZi AyNuQ"
415456
>
416457
<button
458+
aria-current="false"
459+
aria-label="Step 6"
417460
className="sc-dkzDqf iyRspZ"
418461
onClick={[Function]}
419462
>
@@ -424,6 +467,8 @@ exports[`ProgressBar matches snapshot when status step is active 1`] = `
424467
className="sc-gsnTZi AyNuQ"
425468
>
426469
<button
470+
aria-current="location"
471+
aria-label="Assignment status"
427472
className="sc-dkzDqf ejGnvX"
428473
onClick={[Function]}
429474
>
@@ -441,5 +486,5 @@ exports[`ProgressBar matches snapshot when status step is active 1`] = `
441486
</svg>
442487
</button>
443488
</span>
444-
</div>
489+
</nav>
445490
`;

0 commit comments

Comments
 (0)