Fix checkbox and radio input validation positioning
Summary
Ref: https://github.com/primer/brand/issues/203
This PR fixes a bug with the positioning of the validation message for checkbox and radio inputs inside a FormControl component. This was originally reported as just an issue for checkboxes, but I also noticed it impacted radio inputs as well, so this PR fixes the issue for both types of inputs.
List of notable changes:
- updated the .FormControl--checkbox css class to use flex-grid styling instead of flexbox with row-reverse
-
added
FormControl-validation-checkboxcss class to position the validation message for checkboxes and radio buttons. -
added the
FormControl-validation-checkboxclass to any FormControlValidation children only when there is a checkbox or radio input. - added a storybook story for validation with checkbox and radio inputs to illustrate what these scenarios look like.
- updated the CSS classes for the wrappers for radio and checkbox inputs to conditionally use the grid-row property when their parent element is a form control element.
What should reviewers focus on?
- What do you think of this approach of using CSS to fix this issue? I saw there was a previous PR that made an attempt to modify the FormControl component's composition and place a container around the input and its label so the validation message would no longer share a parent with them and therefore not be affected by the row-reverse property on the parent container. This CSS only approach seemed a little simpler.
Steps to test:
- Open the FormControl component in CI-deployed preview environment
- Go to 'w/ Error Validation with Checkbox - Playground' and 'w/ Error Validation with Radio - Playground' story in Storybook
- Verify that the validation now appears below the checkbox and radio inputs instead of next to them.
Supporting resources (related issues, external links, etc):
- Related issue: https://github.com/primer/brand/issues/203
- Previous PR that attempted to fix this issue: https://github.com/primer/brand/pull/513
Contributor checklist:
- [ ] All new and existing CI checks pass
- [ ] Tests prove that the feature works and covers both happy and unhappy paths
- [ ] Any drop in coverage, breaking changes or regressions have been documented above
- [ ] New visual snapshots have been generated / updated for any UI changes
- [ ] All developer debugging and non-functional logging has been removed
- [ ] Related issues have been referenced in the PR description
Reviewer checklist:
- [ ] Check that pull request and proposed changes adhere to our contribution guidelines and code of conduct
- [ ] Check that tests prove the feature works and covers both happy and unhappy paths
- [ ] Check that there aren't other open Pull Requests for the same update/change
Screenshots:
Please try to provide before and after screenshots or videos
| Before | After |
|---|---|
|
|
|
|
|
|
🦋 Changeset detected
Latest commit: 073ec821d10e1b32b36bebd8468d1be1ebd035b7
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 6 packages
| Name | Type |
|---|---|
| @primer/react-brand | Patch |
| @primer/brand-primitives | Patch |
| @primer/brand-e2e | Patch |
| @primer/brand-fonts | Patch |
| @primer/brand-config | Patch |
| @primer/brand-storybook | 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
🟢 No design token changes found
⚠️ Visual differences found
Our visual comparison tests found UI differences.
Please review the differences by using the test artifacts to ensure that the changes were intentional.
Artifacts can be downloaded and reviewed locally.
Download links are available at the bottom of the workflow summary screen.
Example:

If the changes are expected, please run npm run test:visual:update-snapshots to replace the previous fixtures.
@rezrah @joshfarrant I think this is ready for another review. @rezrah and I discussed isolating the changes to just the checkbox inputs, so I made those changes and incorporated all of the previous feedback as well.
Thanks again @MelissaPastore!