Skip to content

Commit

Permalink
make the progress bar accessible as breadcrumbs (#67)
Browse files Browse the repository at this point in the history
* make the progress bar accessible as breadcrumbs

* update snapshots
  • Loading branch information
jivey authored Apr 25, 2024
1 parent e2a52e2 commit c1a6f5e
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 17 deletions.
29 changes: 18 additions & 11 deletions src/components/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faCheck } from '@fortawesome/free-solid-svg-icons/faCheck';
import { faXmark } from '@fortawesome/free-solid-svg-icons/faXmark';

const ProgressBarWrapper = styled.div`
const ProgressBarWrapper = styled.nav`
display: flex;
justify-content: flex-start;
flex-wrap: wrap;
Expand Down Expand Up @@ -131,18 +131,25 @@ export type ProgressBarItemVariant = 'isCorrect' | 'isIncorrect' | 'isStatus' |

export const ProgressBarItem = <S extends {variant: ProgressBarItemVariant}>({index, isActive, step, goToStep}: ProgressBarItemProps<S>) =>
<StyledItemWrapper>
<StyledItem variant={step.variant} isActive={isActive} onClick={() => goToStep(index, step)}>
<StyledItem
variant={step.variant}
isActive={isActive}
onClick={() => goToStep(index, step)}
aria-current={isActive ? 'location' : 'false'}
aria-label={step.variant === 'isStatus' ? 'Assignment status' : `Step ${index + 1}` }
>
{step.variant === 'isStatus' ? <FlagIcon /> : index + 1}
</StyledItem>
<ItemIcon variant={step.variant} />
</StyledItemWrapper>;

export const ProgressBar = <S extends {variant: ProgressBarItemVariant}>({ steps, activeIndex, goToStep }: ProgressBarProps<S>) => <ProgressBarWrapper>
{steps.map((step, index) => <ProgressBarItem
key={index}
index={index}
isActive={index === activeIndex}
step={step}
goToStep={goToStep}
/>)}
</ProgressBarWrapper>;
export const ProgressBar = <S extends {variant: ProgressBarItemVariant}>({ steps, activeIndex, goToStep }: ProgressBarProps<S>) =>
<ProgressBarWrapper aria-label="Breadcrumbs">
{steps.map((step, index) => <ProgressBarItem
key={index}
index={index}
isActive={index === activeIndex}
step={step}
goToStep={goToStep}
/>)}
</ProgressBarWrapper>;
57 changes: 51 additions & 6 deletions src/components/__snapshots__/ProgressBar.spec.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ProgressBar matches snapshot 1`] = `
<div
<nav
aria-label="Breadcrumbs"
className="sc-bczRLJ bQqPBP"
>
<span
className="sc-gsnTZi AyNuQ"
>
<button
aria-current="false"
aria-label="Step 1"
className="sc-dkzDqf KrxmS"
onClick={[Function]}
>
Expand Down Expand Up @@ -38,6 +41,8 @@ exports[`ProgressBar matches snapshot 1`] = `
className="sc-gsnTZi AyNuQ"
>
<button
aria-current="false"
aria-label="Step 2"
className="sc-dkzDqf gKblal"
onClick={[Function]}
>
Expand Down Expand Up @@ -68,6 +73,8 @@ exports[`ProgressBar matches snapshot 1`] = `
className="sc-gsnTZi AyNuQ"
>
<button
aria-current="location"
aria-label="Step 3"
className="sc-dkzDqf hmFFbY"
onClick={[Function]}
>
Expand Down Expand Up @@ -98,6 +105,8 @@ exports[`ProgressBar matches snapshot 1`] = `
className="sc-gsnTZi AyNuQ"
>
<button
aria-current="false"
aria-label="Step 4"
className="sc-dkzDqf iyRspZ"
onClick={[Function]}
>
Expand All @@ -108,6 +117,8 @@ exports[`ProgressBar matches snapshot 1`] = `
className="sc-gsnTZi AyNuQ"
>
<button
aria-current="false"
aria-label="Step 5"
className="sc-dkzDqf iyRspZ"
onClick={[Function]}
>
Expand All @@ -118,6 +129,8 @@ exports[`ProgressBar matches snapshot 1`] = `
className="sc-gsnTZi AyNuQ"
>
<button
aria-current="false"
aria-label="Step 6"
className="sc-dkzDqf iyRspZ"
onClick={[Function]}
>
Expand All @@ -128,6 +141,8 @@ exports[`ProgressBar matches snapshot 1`] = `
className="sc-gsnTZi AyNuQ"
>
<button
aria-current="false"
aria-label="Assignment status"
className="sc-dkzDqf iyRspZ"
onClick={[Function]}
>
Expand All @@ -145,17 +160,20 @@ exports[`ProgressBar matches snapshot 1`] = `
</svg>
</button>
</span>
</div>
</nav>
`;

exports[`ProgressBar matches snapshot when active step is incomplete 1`] = `
<div
<nav
aria-label="Breadcrumbs"
className="sc-bczRLJ bQqPBP"
>
<span
className="sc-gsnTZi AyNuQ"
>
<button
aria-current="false"
aria-label="Step 1"
className="sc-dkzDqf KrxmS"
onClick={[Function]}
>
Expand Down Expand Up @@ -186,6 +204,8 @@ exports[`ProgressBar matches snapshot when active step is incomplete 1`] = `
className="sc-gsnTZi AyNuQ"
>
<button
aria-current="false"
aria-label="Step 2"
className="sc-dkzDqf gKblal"
onClick={[Function]}
>
Expand Down Expand Up @@ -216,6 +236,8 @@ exports[`ProgressBar matches snapshot when active step is incomplete 1`] = `
className="sc-gsnTZi AyNuQ"
>
<button
aria-current="false"
aria-label="Step 3"
className="sc-dkzDqf KrxmS"
onClick={[Function]}
>
Expand Down Expand Up @@ -246,6 +268,8 @@ exports[`ProgressBar matches snapshot when active step is incomplete 1`] = `
className="sc-gsnTZi AyNuQ"
>
<button
aria-current="location"
aria-label="Step 4"
className="sc-dkzDqf ejGnvX"
onClick={[Function]}
>
Expand All @@ -256,6 +280,8 @@ exports[`ProgressBar matches snapshot when active step is incomplete 1`] = `
className="sc-gsnTZi AyNuQ"
>
<button
aria-current="false"
aria-label="Step 5"
className="sc-dkzDqf iyRspZ"
onClick={[Function]}
>
Expand All @@ -266,6 +292,8 @@ exports[`ProgressBar matches snapshot when active step is incomplete 1`] = `
className="sc-gsnTZi AyNuQ"
>
<button
aria-current="false"
aria-label="Step 6"
className="sc-dkzDqf iyRspZ"
onClick={[Function]}
>
Expand All @@ -276,6 +304,8 @@ exports[`ProgressBar matches snapshot when active step is incomplete 1`] = `
className="sc-gsnTZi AyNuQ"
>
<button
aria-current="false"
aria-label="Assignment status"
className="sc-dkzDqf iyRspZ"
onClick={[Function]}
>
Expand All @@ -293,17 +323,20 @@ exports[`ProgressBar matches snapshot when active step is incomplete 1`] = `
</svg>
</button>
</span>
</div>
</nav>
`;

exports[`ProgressBar matches snapshot when status step is active 1`] = `
<div
<nav
aria-label="Breadcrumbs"
className="sc-bczRLJ bQqPBP"
>
<span
className="sc-gsnTZi AyNuQ"
>
<button
aria-current="false"
aria-label="Step 1"
className="sc-dkzDqf KrxmS"
onClick={[Function]}
>
Expand Down Expand Up @@ -334,6 +367,8 @@ exports[`ProgressBar matches snapshot when status step is active 1`] = `
className="sc-gsnTZi AyNuQ"
>
<button
aria-current="false"
aria-label="Step 2"
className="sc-dkzDqf gKblal"
onClick={[Function]}
>
Expand Down Expand Up @@ -364,6 +399,8 @@ exports[`ProgressBar matches snapshot when status step is active 1`] = `
className="sc-gsnTZi AyNuQ"
>
<button
aria-current="false"
aria-label="Step 3"
className="sc-dkzDqf KrxmS"
onClick={[Function]}
>
Expand Down Expand Up @@ -394,6 +431,8 @@ exports[`ProgressBar matches snapshot when status step is active 1`] = `
className="sc-gsnTZi AyNuQ"
>
<button
aria-current="false"
aria-label="Step 4"
className="sc-dkzDqf iyRspZ"
onClick={[Function]}
>
Expand All @@ -404,6 +443,8 @@ exports[`ProgressBar matches snapshot when status step is active 1`] = `
className="sc-gsnTZi AyNuQ"
>
<button
aria-current="false"
aria-label="Step 5"
className="sc-dkzDqf iyRspZ"
onClick={[Function]}
>
Expand All @@ -414,6 +455,8 @@ exports[`ProgressBar matches snapshot when status step is active 1`] = `
className="sc-gsnTZi AyNuQ"
>
<button
aria-current="false"
aria-label="Step 6"
className="sc-dkzDqf iyRspZ"
onClick={[Function]}
>
Expand All @@ -424,6 +467,8 @@ exports[`ProgressBar matches snapshot when status step is active 1`] = `
className="sc-gsnTZi AyNuQ"
>
<button
aria-current="location"
aria-label="Assignment status"
className="sc-dkzDqf ejGnvX"
onClick={[Function]}
>
Expand All @@ -441,5 +486,5 @@ exports[`ProgressBar matches snapshot when status step is active 1`] = `
</svg>
</button>
</span>
</div>
</nav>
`;

0 comments on commit c1a6f5e

Please sign in to comment.