Skip to content
Open
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/horizontal-form-control-inputs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Fix duplicate input rendering in horizontal FormControl layouts.
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
11 changes: 11 additions & 0 deletions packages/react/src/FormControl/__tests__/FormControl.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ describe('FormControl', () => {
expect(leadingVisual).not.toBeNull()
})

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

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

describe('vertically stacked layout (default)', () => {
describe('rendering', () => {
it('renders with a hidden label', () => {
Expand Down
Loading