Skip to content

Commit

Permalink
feat: Allow intrinsic elements to be passed to Fieldset (#1862)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonlenz authored Jan 3, 2022
1 parent 6e6a5df commit 85a0092
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/components/forms/Fieldset/Fieldset.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ describe('Fieldset component', () => {
expect(queryByText('My Fieldset')).toBeInTheDocument()
})

it('accepts fieldset intrinsic props', () => {
const { queryByText } = render(
<Fieldset aria-live="polite">My Fieldset</Fieldset>
)

const myFieldset = queryByText('My Fieldset')

expect(myFieldset).toBeInTheDocument()
expect(myFieldset).toHaveAttribute('aria-live', 'polite')
})

describe('renders uswds classes', () => {
it('renders legend with class usa-legend by default', () => {
const { queryByTestId, getByText } = render(
Expand Down
5 changes: 3 additions & 2 deletions src/components/forms/Fieldset/Fieldset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const Fieldset = ({
className,
legendSrOnly,
legendStyle = 'default',
}: FieldsetProps): React.ReactElement => {
...fieldsetProps
}: FieldsetProps & JSX.IntrinsicElements['fieldset']): React.ReactElement => {
const classes = classnames('usa-fieldset', className)

if (legendSrOnly) {
Expand All @@ -35,7 +36,7 @@ export const Fieldset = ({
})

return (
<fieldset data-testid="fieldset" className={classes}>
<fieldset data-testid="fieldset" className={classes} {...fieldsetProps}>
{legend && <legend className={legendClasses}>{legend}</legend>}
{children}
</fieldset>
Expand Down

0 comments on commit 85a0092

Please sign in to comment.