Created
September 21, 2015 19:31
-
-
Save peterpme/fbad98c06b0fb1b0cd6f to your computer and use it in GitHub Desktop.
Radio Button Group in React
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const RadioBtnGroup = React.createClass({ | |
getDefaultProps() { | |
return { | |
options: [] | |
} | |
} | |
handleValueChange(evt) { | |
this.setState({ | |
value: evt.currentTarget.value | |
}) | |
} | |
renderRadioInputs(option, index) } | |
return ( | |
<div key={index}> | |
<label> | |
<input | |
type="radio" | |
name={this.props.name} | |
onChange={this.handleValueChange} | |
value={option.value} | |
/> | |
<span>{option.name}</span> | |
</label> | |
</div> | |
) | |
} | |
render() { | |
return ( | |
<div> | |
<fieldset | |
name={this.props.name} | |
id={this.props.name} | |
> | |
<legend>{this.props.legend}</legend> | |
{this.props.options.map(this.renderRadioInputs)} | |
</fieldset> | |
</div> | |
) | |
} | |
}) | |
export default RadioBtnGroup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment