-
Notifications
You must be signed in to change notification settings - Fork 33
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
Add CheckboxGroup and RadioGroup components #830
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 8e91013 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 16 out of 26 changed files in this pull request and generated no suggestions.
Files not reviewed (10)
- packages/react/src/forms/InputGroup/InputGroup.module.css: Language not supported
- packages/react/src/forms/RadioGroup/RadioGroup.tsx: Evaluated as low risk
- packages/react/src/forms/CheckboxGroup/CheckboxGroup.stories.tsx: Evaluated as low risk
- packages/react/src/forms/CheckboxGroup/CheckboxGroup.test.tsx: Evaluated as low risk
- packages/react/src/forms/index.ts: Evaluated as low risk
- packages/react/src/forms/CheckboxGroup/index.ts: Evaluated as low risk
- .changeset/popular-seas-yawn.md: Evaluated as low risk
- packages/react/src/forms/InputGroup/index.ts: Evaluated as low risk
- packages/react/src/forms/RadioGroup/RadioGroup.stories.tsx: Evaluated as low risk
- packages/react/src/forms/RadioGroup/index.ts: Evaluated as low risk
Comments skipped due to low confidence (3)
packages/react/src/forms/CheckboxGroup/CheckboxGroup.visual.spec.ts:8
- Consider removing the eslint-disable comment and ensuring that the code adheres to the i18n-text/no-en rule.
// eslint-disable-next-line i18n-text/no-en
packages/react/src/forms/InputGroup/InputGroup.tsx:20
- The error message should be more concise and specific, e.g., 'useInputGroup must be used within an InputGroupProvider.'
throw new Error('useInputGroup must be used within an InputGroupProvider. Did you forget to wrap your component in a <InputGroupProvider>?')
packages/react/src/forms/CheckboxGroup/CheckboxGroup.tsx:14
- [nitpick] Consider adding a comment explaining that CheckboxGroup is currently just an alias for InputGroup to provide context for future maintainers.
export const CheckboxGroup = InputGroup
Tip: Copilot only keeps its highest confidence comments to reduce noise and keep you focused. Learn more
|
5be3a2e
to
810a183
Compare
|
||
.ControlGroup__validation-icon--success { | ||
position: relative; | ||
top: -1.6px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, pulled from FormControl to keep things consistent
Happy to modify it if you'd prefer though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, we've had this conversation before, just in the other direction 😄
It was 1px, but after a brief conversation (here) we settled on 1.6px.
4f50c91#diff-66f88db62ba93924cf6de6ae216861c98149f0122e02c93173b5778c43cd4b57R95-R98
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay 🤣 .. let's keep it the same then.. i used a visual guide in the other screenshot so that's probably more correct. Although could this be a bit different because the text is 100 vs 200?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although could this be a bit different because the text is 100 vs 200?
Yea I just realised the same thing, I think that accounts for the difference. I've adjusted the values visually to account for the smaller text size, but if you want to have another look and possibly tweak them then just let me know and I'll update the values in the PR
}, | ||
} | ||
|
||
export const Inline: Story = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we move this story into a separate CheckboxGroup.features.stories.tsx
file and organize it inside a CheckboxGroup/Examples
or CheckboxGroup/Features
subfolder please? Probably former in this case as it's not a feature of the component.
I know the other form control stories don't follow this format. It's because those predate the Primer ADR around story organization and also need to be updated at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know what you think about my approach here
I wanted to keep the interactivity of the Inline story as it currently works nicely with the controls, but I didn't want to duplicate the controls set up (args
, argTypes
) across both files, so I've brought the meta
object defined in the main story file into the examples
file and reused it there, just with a modified title
.
lmk if you're happy with this
packages/react/src/forms/CheckboxGroup/CheckboxGroup.stories.tsx
Outdated
Show resolved
Hide resolved
|
||
export default meta | ||
|
||
type Story = StoryObj<MetaProps> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does Storybook provide a built-in type for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StoryObj
is the built-in, recommended type. See the example in the docs here.
<Radio name="demo" value="three" /> | ||
</FormControl> | ||
|
||
<RadioGroup.Validation variant="success">Great job!</RadioGroup.Validation> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a Jest warning related to validation prop in the test logs. Possible to take a look at fixing that please?
https://github.com/primer/brand/actions/runs/12053705065/job/33609998572?pr=830#step:10:53
(Doesn't seem to be happening for CheckboxGroup FWIW)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yea, thanks for raising this. I spotted this the other day and I meant to dig into it more.
It boils down to the fact that, in FormControl.tsx
, we forward validationStatus
to the Radio component, but Radio doesn't implement it, so it just ends up in the HTML.
I'm not sure if I can just stop FormControl from forwarding validationStatus
to Radio, or whether Radio should actually be using it to set aria-invalid
as Checkbox does.
My inclination is to tackle this in its own PR as it's not an issue introduced in this PR, wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about it though, I'm not entirely sure how an individual Radio control (not a group, just a single control) could ever be invalid 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed the prop forwarding and resolved the console.error
in the tests. Removing the forwarding hasn't modified the behaviour of FormControl or Radio in any way as the forwarded prop was never used.
|
||
The `RadioGroup` family of components provide a way to group related [Radio](/components/Radio) components together with supporting content such as labels, captions, and validation messages. It creates a semantic fieldset structure that helps maintain proper form hierarchy and accessibility. | ||
|
||
> **Important**: When using Radio components within a RadioGroup, ensure you provide the same `name` prop to each Radio. This ensures they are correctly grouped and only one option can be selected at a time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> **Important**: When using Radio components within a RadioGroup, ensure you provide the same `name` prop to each Radio. This ensures they are correctly grouped and only one option can be selected at a time. | |
> **Important**: When using Radio components within a radio group, ensure you provide the same `name` prop to each Radio. This ensures they are correctly grouped and only one option can be selected at a time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just replaced this file with a (near) copy of PRC, lmk what you think
Summary
Adds
CheckboxGroup
andRadioGroup
components which, for the time being, are just implementations of the new privateControlGroup
component. These components allow us to groupRadio
andCheckbox
components using a<fieldset>
and label them with a<legend>
, providing a more accessible and semantic way to group related form elements.List of notable changes:
ControlGroup
component (alternate name suggestions welcome)CheckboxGroup
andRadioGroup
components, tests, and storiesStill to do (in future PRs)
What should reviewers focus on?
Steps to test:
Supporting resources (related issues, external links, etc):
Contributor checklist:
update snapshots
label to the PR)Reviewer checklist:
Screenshots: