Skip to content

Commit

Permalink
RadioButtonGroup can handle non-RadioButton children; resolves mui#2225
Browse files Browse the repository at this point in the history
  • Loading branch information
bshyong committed Mar 7, 2016
1 parent 133f660 commit ef459ae
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions src/radio-button-group.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,38 @@ const RadioButtonGroup = React.createClass({
}
},

_radioButtonMapFunc(option) {
if (option.props.children === undefined) {
let {
name,
value,
label,
onCheck,
...other,
} = option.props;
if (option.type.displayName === 'RadioButton') {
return <RadioButton
{...other}
ref={option.props.value}
name={this.props.name}
key={option.props.value}
value={option.props.value}
label={option.props.label}
labelPosition={this.props.labelPosition}
onCheck={this._onChange}
checked={option.props.value === this.state.selected}/>;
}
}

return {
...option,
props: {
...option.props,
children: React.Children.map(option.props.children, this.radioButtonMapFunc, this)
}
}
},

handleChange(event, newSelection) {
this._updateRadioButtons(newSelection);

Expand Down Expand Up @@ -143,27 +175,7 @@ const RadioButtonGroup = React.createClass({
} = this.state.muiTheme;

const options = React.Children.map(this.props.children, (option) => {
const {
name,
value,
label,
onCheck,
...other,
} = option.props;

return (
<RadioButton
{...other}
ref={option.props.value}
name={this.props.name}
key={option.props.value}
value={option.props.value}
label={option.props.label}
labelPosition={this.props.labelPosition}
onCheck={this.handleChange}
checked={option.props.value === this.state.selected}
/>
);
return this._radioButtonMapFunc(option);
}, this);

return (
Expand Down

0 comments on commit ef459ae

Please sign in to comment.