Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make the progress bar accessible as breadcrumbs #67

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
`;
Loading