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

feat: accept prop for heading level (#1751) #1865

Merged
merged 3 commits into from
Jan 7, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,13 @@ export const smallCounters = (): React.ReactElement => (
<StepIndicatorStep label="Review and submit" />
</StepIndicator>
)

export const customHeadingLevel = (): React.ReactElement => (
<StepIndicator headingLevel="h2">
<StepIndicatorStep label="Personal information" status="complete" />
<StepIndicatorStep label="Household status" status="complete" />
<StepIndicatorStep label="Supporting documents" status="current" />
<StepIndicatorStep label="Signature" />
<StepIndicatorStep label="Review and submit" />
</StepIndicator>
)
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,34 @@ describe('StepIndicator component', () => {
expect(queryByText(step3)).toBeInTheDocument()
expect(getByRole('list')).toHaveClass('usa-step-indicator__segments')
})

it('renders properly with a passed in heading level', () => {
const { getByRole, queryByTestId } = render(
<StepIndicator headingLevel="h2">
<StepIndicatorStep label={step1} status="complete" />
<StepIndicatorStep label={step2} status="current" />
<StepIndicatorStep label={step3} status="incomplete" />
</StepIndicator>
)

const stepIndicator = queryByTestId('step-indicator')

expect(stepIndicator).toBeInTheDocument()
expect(getByRole('heading', { level: 2 })).toBeInTheDocument()
})

it('renders properly with a default heading level', () => {
const { getByRole, queryByTestId } = render(
<StepIndicator>
<StepIndicatorStep label={step1} status="complete" />
<StepIndicatorStep label={step2} status="current" />
<StepIndicatorStep label={step3} status="incomplete" />
</StepIndicator>
)

const stepIndicator = queryByTestId('step-indicator')

expect(stepIndicator).toBeInTheDocument()
expect(getByRole('heading', { level: 4 })).toBeInTheDocument()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface StepIndicatorProps {
className?: string
divProps?: JSX.IntrinsicElements['div']
listProps?: JSX.IntrinsicElements['ol']
headingLevel?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
}
export const StepIndicator = (
props: StepIndicatorProps
Expand All @@ -22,8 +23,11 @@ export const StepIndicator = (
className,
divProps,
listProps,
headingLevel = 'h4',
} = props

const Heading = headingLevel

const classes = classnames(
'usa-step-indicator',
{
Expand Down Expand Up @@ -54,7 +58,7 @@ export const StepIndicator = (
{children}
</ol>
<div className="usa-step-indicator__header">
<h4 className="usa-step-indicator__heading">
<Heading className="usa-step-indicator__heading">
<span className="usa-step-indicator__heading-counter">
<span className="usa-sr-only">Step</span>
<span className="usa-step-indicator__current-step">
Expand All @@ -67,7 +71,7 @@ export const StepIndicator = (
<span className="usa-step-indicator__heading-text">
{currentStepLabel}
</span>
</h4>
</Heading>
</div>
</div>
)
Expand Down