Skip to content

fix(FormControl): prevent duplicate input rendering in horizontal layout - #8508

Merged
tay1orjones merged 3 commits into
primer:mainfrom
namangoyal176-10:fix/8487-formcontrol-horizontal-input-duplicate
Oct 14, 2026
Merged

tay1orjones merged 3 commits into
primer:mainfrom
namangoyal176-10:fix/8487-formcontrol-horizontal-input-duplicate

Conversation

@namangoyal176-10

Copy link
Copy Markdown
Contributor

Summary

Fixes an issue where FormControl with layout="horizontal" renders duplicate non-choice inputs (such as TextInput, Textarea, Select, Autocomplete).

Root Cause

In packages/react/src/FormControl/FormControl.tsx, InputChildren clones and renders InputComponent into classes.ControlChoiceInputs. However, the subsequent filter over childrenWithoutSlots only 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 all expectedInputComponents.

Changes

  • Updated the childrenWithoutSlots filter in InputChildren to exclude all expectedInputComponents (matching the vertical layout branch behavior).
    • Added a changeset patch for @primer/react.
    • Added a regression test in FormControl.test.tsx verifying that only one input is rendered when layout="horizontal" is used with a non-choice input.

Testing

  • Ran Vitest:
  • npx vitest run packages/react/src/FormControl/__tests__/
  • Result: 3 test files passed, 45 tests passed.
    • Verified regression test failed before fix (expected 1 textbox, received 2) and passed after fix.
    • Ran TypeScript check:
  • npx tsc --noEmit -> 0 errors.
    • Ran ESLint:
  • npx eslint packages/react/src/FormControl/FormControl.tsx packages/react/src/FormControl/__tests__/FormControl.test.tsx -> 0 errors.
    • Ran Prettier:
  • All matched files use Prettier code style.
    Closes FormControl renders duplicate non-choice inputs when layout="horizontal" #8487

@namangoyal176-10
namangoyal176-10 requested a review from a team as a code owner October 6, 2026 17:47
@changeset-bot

changeset-bot Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 75fe563

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.

@tay1orjones tay1orjones left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

@tay1orjones

Copy link
Copy Markdown
Contributor

Integration tests look good #8523 (comment), so skipping here

@tay1orjones tay1orjones added the integration-tests: skipped manually Changes in this PR do not require an integration test label Oct 7, 2026
@tay1orjones
tay1orjones enabled auto-merge October 14, 2026 16:22
@tay1orjones tay1orjones added integration-tests: skipped manually Changes in this PR do not require an integration test and removed integration-tests: skipped manually Changes in this PR do not require an integration test labels Oct 14, 2026
@tay1orjones tay1orjones added the integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh label Oct 14, 2026
@primer-integration

Copy link
Copy Markdown

Integration test results from github/github-ui PR:

Passed  Changes   Passed
Passed  CI   Passed
Passed  VRT   Passed
Passed  Projects   Passed

All checks passed!

@llastflowers llastflowers removed the integration-tests: skipped manually Changes in this PR do not require an integration test label Oct 14, 2026
@llastflowers

Copy link
Copy Markdown
Contributor

.skip-integration-checks

@tay1orjones
tay1orjones added this pull request to the merge queue Oct 14, 2026
Merged via the queue into primer:main with commit f71dce4 Oct 14, 2026
51 of 61 checks passed
@primer primer Bot mentioned this pull request Oct 14, 2026

This branch was successfully deployed

1 active deployment
github-pages — 75fe5634 Deployed Oct 14, 2026 by francinelucca via deploy-preview #29990
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FormControl renders duplicate non-choice inputs when layout="horizontal"

5 participants