question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Booleans in Radio groups

See original GitHub issue
  • This is not a v0.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

Since 3.2.1 Radio elements can have a boolean value. Great! Have been waiting for this functionality for a while. Tested it immediately and found some issues:

  1. FormControlLabel should support numbers & booleans now as well. This gives a warning now.
<FormControlLabel
    value={false}
    control={<Radio />}
    label="green"
/>
  1. When using the boolean values, the value in onChange function of RadioGroup gets transformed to String anyway. Edit create-react-app

Your Environment

Tech Version
Material-UI v3.2.1
React latest
Browser Chrome

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
oliviertassinaricommented, Oct 15, 2018

@karensg The idea behind #13173 was to allow people have the native input do the type casting to a string. We try not to be opinionated around how the native input behaves. Another way to see it, is that we trust React for having picked the best tradeoff. I can easily imagine the behavior you are looking for being rolled out to all React users. Thanks for raising the concern.

0reactions
snekocommented, Dec 19, 2022

I struggled a bit with React Hook Form + Zod, since I wanted to manage booleans in my business logic, but the templating was messing with strings.

Don’t know if it can help but here my “workaround”: https://stackoverflow.com/a/74854174/3608410

Read more comments on GitHub >

github_iconTop Results From Across the Web

Booleans in Radio groups #13250 - mui/material-ui - GitHub
Since 3.2.1 Radio elements can have a boolean value. Great! Have been waiting for this functionality for a while.
Read more >
ReactJS: How to use boolean values in radio buttons?
What is the proper way to use boolean data in radio buttons. The values will be converted from booleans to strings if used...
Read more >
<input type="radio"> - HTML: HyperText Markup Language
A Boolean attribute which, if present, indicates that this radio button is the default selected one in the group. Unlike other browsers, ...
Read more >
Radio Button group with boolean binding shows defaut as ...
Hi ALL,. I have a radio button group with boolean variable binding. Even though variable is initialized by default false(No) is showing in...
Read more >
How can I store a radio button value as a boolean?
You can set boolean values to display as 1 = yes and 0 = no, but unfortunately you can't do this with radio...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found