@@ -36,17 +36,13 @@ var RadioGroup = React.createClass({
36
36
onChange : React . PropTypes . func
37
37
} ,
38
38
39
- getDefaultProps : function ( ) {
40
- return { onChange : ( ) => null } ;
41
- } ,
39
+ render : function ( ) {
40
+ var { name, children, onChange, ...others } = this . props ;
42
41
43
- onChange : function ( e ) {
44
- this . props . onChange ( e . target . value ) ;
45
- } ,
42
+ children = React . Children . map ( children ,
43
+ ( child ) => cloneWithProps ( child , { name , onChange : onChange } )
44
+ ) ;
46
45
47
- render : function ( ) {
48
- var { name, children, ...others } = this . props ;
49
- children = React . Children . map ( children , ( child ) => cloneWithProps ( child , { name, onChange : this . onChange } ) ) ;
50
46
var props = mergeProps ( others , { className : 'radio-group' } ) ;
51
47
52
48
@@ -110,8 +106,8 @@ Similar to the `name` property, the `onChange` handlers is passed down to all ch
110
106
var MyComponent = React.createClass({
111
107
getInitialState: function() { return {selection: null}; },
112
108
113
- change: function(value ) {
114
- this.setState({selection: value});
109
+ change: function(e ) {
110
+ this.setState({selection: e.target. value});
115
111
},
116
112
117
113
render: function() {
@@ -129,15 +125,19 @@ var MyComponent = React.createClass({
129
125
</RadioGroup>
130
126
</Col>
131
127
</div>
132
- {this.state.selection === 'special' && (<div className="form-group">
133
- <Col md={3}>
134
- <label>Stuff that appears</label>
135
- </Col>
136
- <Col md={21}>
137
- <label htmlFor="exampleInputEmail1">Email address</label>
138
- <input type="email" className="form-control" id="exampleInputEmail1" placeholder="Enter email" />
139
- </Col>
140
- </div>)}
128
+ {this.state.selection === 'special' && (
129
+
130
+ <div className="form-group">
131
+ <Col md={3}>
132
+ <label>Stuff that appears</label>
133
+ </Col>
134
+ <Col md={21}>
135
+ <label htmlFor="exampleInputEmail1">Email address</label>
136
+ <input type="email" className="form-control" id="exampleInputEmail1" placeholder="Enter email" />
137
+ </Col>
138
+ </div>
139
+
140
+ )}
141
141
</form>
142
142
);
143
143
}
0 commit comments