Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix checkbox and radio input validation positioning #728

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

MelissaPastore
Copy link
Contributor

@MelissaPastore MelissaPastore commented Sep 3, 2024

Summary

Ref: #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-checkbox css class to position the validation message for checkboxes and radio buttons.
  • added the FormControl-validation-checkbox class 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 but I'm not sure if it's good practice to have a position: absolute element within a flex container?

Steps to test:

  1. Open the FormControl component in CI-deployed preview environment
  2. Go to 'w/ Error Validation with Checkbox - Playground' and 'w/ Error Validation with Radio - Playground' story in Storybook
  3. Verify that the validation now appears below the checkbox and radio inputs instead of next to them.

Supporting resources (related issues, external links, etc):

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

Copy link

changeset-bot bot commented Sep 3, 2024

🦋 Changeset detected

Latest commit: 6fcda52

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

Copy link
Contributor

github-actions bot commented Sep 3, 2024

🟢 No design token changes found

Copy link
Contributor

github-actions bot commented Sep 3, 2024

⚠️ 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:

artifacts section of workflow run

If the changes are expected, please run npm run test:visual:update-snapshots to replace the previous fixtures.

Review visual differences

@MelissaPastore MelissaPastore changed the title Fix checkbox validation positioning Fix checkbox and radio input validation positioning Sep 3, 2024
<>
<Stack direction={{narrow: 'vertical', regular: 'horizontal'}} gap="condensed" padding="condensed">
<FormControl>
<FormControl
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is pretty much borrowed from the CheckboxPlayground implementation so I could re-use this component for the example with a validation message.

@@ -5,6 +5,11 @@
position: relative;
}

[class*='FormControl'] .Checkbox-wrapper,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This might be overkill but I wasn't sure if we wanted to always apply the grid-row to the wrapper for the input or only do this when its parent is a form control element?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants