Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/fix-formcontrol-horizontal-input-duplicate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

FormControl: Prevent duplicate input rendering when layout is horizontal with non-choice inputs
4 changes: 3 additions & 1 deletion packages/react/src/FormControl/FormControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ const FormControl = React.forwardRef<HTMLDivElement, FormControlProps>(
{childrenWithoutSlots.filter(
child =>
React.isValidElement(child) &&
![Checkbox, Radio].some(inputComponent => child.type === inputComponent || isSlot(child, inputComponent)),
!expectedInputComponents.some(
inputComponent => child.type === inputComponent || isSlot(child, inputComponent),
),
)}
</div>
{slots.leadingVisual ? (
Expand Down
13 changes: 13 additions & 0 deletions packages/react/src/FormControl/__tests__/FormControl.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -686,4 +686,17 @@ describe('FormControl', () => {
})
})
})

describe('horizontal layout', () => {
it('renders only one input when layout is horizontal with a non-choice input', () => {
const {getAllByRole} = render(
<FormControl layout="horizontal">
<FormControl.Label>{LABEL_TEXT}</FormControl.Label>
<TextInput />
</FormControl>,
)

expect(getAllByRole('textbox')).toHaveLength(1)
})
})
})
Loading