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: null child crashes RadioButtonGroup (#16655) #16691

Merged
merged 4 commits into from
Jun 25, 2024

Conversation

brandones
Copy link
Contributor

Closes #16655

Passing null as a child of a RadioButtonGroup would cause a crash.

Changelog

Changed

This code will no longer crash:

      <RadioButtonGroup name="foo">
        <RadioButton labelText="hey" />
        {null}
      </RadioButtonGroup>

Testing / Reviewing

Try the above code. I included a test.

@brandones brandones requested a review from a team as a code owner June 4, 2024 19:06
Copy link
Contributor

github-actions bot commented Jun 4, 2024

All contributors have signed the DCO.
Posted by the DCO Assistant Lite bot.

@brandones
Copy link
Contributor Author

I have read the DCO document and I hereby sign the DCO.

Copy link

netlify bot commented Jun 4, 2024

Deploy Preview for v11-carbon-react ready!

Name Link
🔨 Latest commit c508c94
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/667acbaf6ff95d0008e2d6f7
😎 Deploy Preview https://deploy-preview-16691--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Jun 4, 2024

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit c508c94
🔍 Latest deploy log https://app.netlify.com/sites/carbon-elements/deploys/667acbaec653f4000843ee26
😎 Deploy Preview https://deploy-preview-16691--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@2nikhiltom 2nikhiltom left a comment

Choose a reason for hiding this comment

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

Hey @brandones .
Thanks for raising this bug and it's fix.

Just trying to understand the use case of below code

<div>
     hi
     <RadioButtonGroup name="foo">
       <RadioButton labelText="hey" />
       {null}
     </RadioButtonGroup>
   </div>

@brandones
Copy link
Contributor Author

@2nikhiltom This kind of thing comes up often when options are not hard-coded.

const { blackIsAllowed } = useConfig();

<div>
     <RadioButtonGroup name="colors">
       <RadioButton labelText="red" value="red" />
       <RadioButton labelText="blue" value="blue" />
       { blackIsAllowed ? <RadioButton labelText="black" value="black" /> : null }
     </RadioButtonGroup>
</div>

Whether you use null, undefined, or false in the blackIsAllowed line, you will get a TypeError.

Also your library simply should not crash with a TypeError on what React considers well-structured input :)

@2nikhiltom
Copy link
Contributor

Hey @brandones ! This looks great, could you resolve conflicts in the branch?

@brandones
Copy link
Contributor Author

Got swooped by @cuppajoey , e582548 . So here's a test if you want it :)

@alisonjoseph alisonjoseph added this pull request to the merge queue Jun 21, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 21, 2024
@tay1orjones tay1orjones added this pull request to the merge queue Jun 25, 2024
Merged via the queue into carbon-design-system:main with commit 929b3bb Jun 25, 2024
22 checks passed
@brandones brandones deleted the issue-16655 branch June 25, 2024 14:34
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.

[Bug]: RadioButtonGroup crashes when passed null or undefined as child
5 participants