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

[added] RadioButton and RadioGroup #962

Closed
wants to merge 1 commit into from

Conversation

aabenoja
Copy link
Member

@aabenoja aabenoja commented Jul 8, 2015

Part of #342.

The RadioGroup might also resolve #365 by keeping track of the selected item.

@aabenoja
Copy link
Member Author

aabenoja commented Jul 8, 2015

This also might against the wrong branch...


return (
<label className={classNames(classes)}>
{input}
Copy link
Member

Choose a reason for hiding this comment

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

the label should probably also add htmlFor if there is an id prop, for better accessibility. We might also want to add id as a requiredForA11y prop to encourage good behavior. I wouldn't assume the prop is there tho to avoid breaking compatibility

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point! I initially didn't implement it since the wrapping automatically associated the radio button with the label and gave me the green light through the WAVE tool. Having the id would certainly be a good enhancement, though I don't think I'll be making it a required prop.

@aabenoja aabenoja force-pushed the radio-split branch 6 times, most recently from af2d07f to dd8f75b Compare July 8, 2015 21:52
@aabenoja
Copy link
Member Author

aabenoja commented Jul 9, 2015

@jquense Got the htmlFor in. Anything else we want to add to this? Any additional functionality we want to add to either the RadioButton or RadioGroup?

@aabenoja
Copy link
Member Author

aabenoja commented Jul 9, 2015

Before we pull this in, how do we want to go about handling a default value?

@joemcbride
Copy link
Member

The pattern I've seen is to provide an initialValue property.

@joemcbride
Copy link
Member

As described here as the initialCount.

@aabenoja aabenoja force-pushed the radio-split branch 2 times, most recently from 9afd2d9 to da5fbef Compare July 9, 2015 21:20
@jquense
Copy link
Member

jquense commented Jul 10, 2015

I think the case of controlled/uncontrolled inputs defaultValue is more idiomatic and mirrors the basic form inputs as well as other rb components which have a similar pattern.

@joemcbride
Copy link
Member

👍 defaultValue works and I think it is good to keep consistency in that regard.

@aabenoja
Copy link
Member Author

👍

@aabenoja aabenoja force-pushed the radio-split branch 5 times, most recently from e747b62 to 1d21e60 Compare July 10, 2015 15:12
<label className={classNames(classes)} htmlFor={id}>
{input}
{label}
</label>
Copy link
Member

Choose a reason for hiding this comment

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

id and label vars from 26 line

const {id, label} = this.props;

are not used anywhere else
why don't just ?

<label className={classNames(classes)} htmlFor={this.props.id}>
  {input}
  {this.props.label}

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks cleaner to me this way, and babel will transform it to this.props.id anyway.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for the clarification 🍒
no problem at all with it. it is just a matter of personal taste 😉

@AlexKVal
Copy link
Member

Boolean props empty default values look odd.
screen shot 2015-07-11 at 2 28 35 pm

Because of the code:

return legend ?
  <legend className={classNames(classes)}>{legend}</legend> :
  null;
'radio': !this.props.inline

their "default" undefined value actually interprets as false.

I propose either to explicitly add them to RadioGroup.defaultProps = {}
(alas there is no smth like @default for documentation generation)
What do you think ?

@jquense
Copy link
Member

jquense commented Jul 11, 2015

I think having empty bool values is fine for now. It might be better to just solve this in the prop documentation code with like a @default or something. That or just default bool props to false. In either case I wouldn't hold up this PR for it.

@aabenoja One thing I might do tho is name the noop function used as the default so it looks clearer in the docs.

let noop = ()=>{}

defaultProps = {
  onChange: noop
}

up to you

@aabenoja
Copy link
Member Author

@AlexKVal I don't see anything necessarily wrong with undefined being interpreted as false, which is something I expect in javascript anyway. It feels pretty asinine to do this for every single boolean, especially when the effect is purely cosmetic.

@jquense I agree, that's something we could do during prop documentation generation. I could sneak that in with this PR. As for the noop that is also a good idea.

@AlexKVal
Copy link
Member

Agree.
Maybe it would be best to let the docs generator to automatically fill default value for booleans if no other default value is provided.

@taion
Copy link
Member

taion commented Jul 11, 2015

A potential problem with filling in a default of e.g. false is that code could potentially do something different for a null-y value than for a false-y one. I think it'd be stupid and broken to do that, but eh. Or I could be wrong - maybe better to require explicit defaults for boolean fields?

@taion taion modified the milestones: v0.25 Release, v0.24.2 Release Jul 30, 2015
@taion
Copy link
Member

taion commented Aug 17, 2015

@aabenoja Did you get a chance to look at @jquense's last two comments?

@aabenoja
Copy link
Member Author

@taion I've been swamped for a while and haven't been able to set aside the time, unfortunately.

@taion
Copy link
Member

taion commented Aug 20, 2015

No worries - going to push this down one more milestone then. Probably better all-around since we have quite a few things for v0.25 already.

@taion taion modified the milestones: v0.26 Release, v0.25 Release Aug 20, 2015
@taion
Copy link
Member

taion commented Sep 15, 2015

Is this essentially good to go now, except for

this also needs to wrap the RadioButton in a FormGroup to be consistent with the old behavior

?

@AlexKVal
Copy link
Member

It seems we should decide the way to go: #962 (comment)

jquense: this also needs to wrap the RadioButton in a FormGroup to be consistent with the old behavior

aabenoja : That my be so, but using FormGroup on RadioButton is causing all sorts of headache, mainly with inline styles.

Wrap it or no ?

@AlexKVal AlexKVal mentioned this pull request Sep 23, 2015
@aabenoja
Copy link
Member Author

Sorry, I've been swamped with other things on my end. In all honestly, using FormGroup around individual RadioButtons doesn't make a lot of sense to me.

@aabenoja aabenoja closed this Sep 25, 2015
@aabenoja aabenoja reopened this Sep 25, 2015
@aabenoja
Copy link
Member Author

Not the button I wanted to hit >.>

@taion taion modified the milestones: v0.27 Release, v0.26 Release Oct 7, 2015
@@ -0,0 +1,39 @@
const SimpleRadioGroup = React.createClass({
getInitialState() {
return {message: undefined};

Choose a reason for hiding this comment

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

i think return {} shoud be better

Choose a reason for hiding this comment

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

({message: undefined}).message=== ({}).message returns true

@bbenezech
Copy link

I need this. I can spend some time on it to get the PR moving.
Can someone sum up the blockers?

poke @jquense @aabenoja

@taion
Copy link
Member

taion commented Jan 26, 2016

@bbenezech At this point, our plan is to revise the <Input> API entirely; we want to drop just about everything on that component except for label, and expose user-composable form groups for everything more customized.

@bbenezech
Copy link

@taion I see. Sounds a bit though for a first commit :/
Good luck and keep up the great work, I appreciate it.

@taion
Copy link
Member

taion commented Apr 1, 2016

Closing this for now – will incorporate this into the form/input rewrite.

@taion taion closed this Apr 1, 2016
@laughnan
Copy link

@taion i see that this has been closed but so is #342. i don't see RadioGroup as being implemented. did something come to fruition from this?

@taion
Copy link
Member

taion commented May 27, 2016

We're just not going to do it for now – if you want something like a radio group, consider a higher-level abstraction like React Formal. For now, we don't see much value in going beyond matching the TWBS API in a thin way here.

@martinjuhasz
Copy link

martinjuhasz commented Aug 14, 2016

For now, we don't see much value in going beyond matching the TWBS API in a thin way here.

Since there is no way to add some radio buttons that toggle a single value and then read the corresponding value with uncontrolled props ( without relying on state) i think there is value in here.
Esprecially on simple forms when there is no state binding needed but you want to toggle a value using multiple radios.

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

Successfully merging this pull request may close these issues.

getValue of Input type="radio" works wrong
9 participants