Repository navigation
fix(FormControl): prevent duplicate input rendering in horizontal layout - #8508
Conversation
🦋 Changeset detectedLatest commit: 75fe563 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
🟢 Approval recommended
The targeted fix is correct, tested, and appropriately documented.
0 open findings
What changed in this PR
Fixes duplicate non-choice inputs in horizontal FormControl layouts.
Changes:
- Filters all recognized input components from remaining children.
- Adds regression coverage and a patch changeset.
| File | Description |
|---|---|
FormControl.tsx |
Prevents duplicate input rendering. |
FormControl.test.tsx |
Tests horizontal non-choice inputs. |
| Changeset | Documents the patch release. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
Integration tests look good #8523 (comment), so skipping here |
|
Integration test results from github/github-ui PR:
All checks passed! |
|
.skip-integration-checks |
Summary
Fixes an issue where
FormControlwithlayout="horizontal"renders duplicate non-choice inputs (such asTextInput,Textarea,Select,Autocomplete).Root Cause
In
packages/react/src/FormControl/FormControl.tsx,InputChildrenclones and rendersInputComponentintoclasses.ControlChoiceInputs. However, the subsequent filter overchildrenWithoutSlotsonly excluded[Checkbox, Radio], allowing non-choice inputs to pass through and render a second time alongside the cloned element. In contrast, the vertical layout branch correctly filters out allexpectedInputComponents.Changes
childrenWithoutSlotsfilter inInputChildrento exclude allexpectedInputComponents(matching the vertical layout branch behavior).@primer/react.FormControl.test.tsxverifying that only one input is rendered whenlayout="horizontal"is used with a non-choice input.Testing
npx vitest run packages/react/src/FormControl/__tests__/npx tsc --noEmit-> 0 errors.npx eslint packages/react/src/FormControl/FormControl.tsx packages/react/src/FormControl/__tests__/FormControl.test.tsx-> 0 errors.Closes FormControl renders duplicate non-choice inputs when layout="horizontal" #8487