mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 09:23:13 +01:00
Small cleanup for renderChildren()
This commit is contained in:
parent
65f7d02e6d
commit
34f3bdcc4e
@ -250,12 +250,15 @@ let Form = React.createClass({
|
||||
},
|
||||
|
||||
renderChildren() {
|
||||
return ReactAddons.Children.map(this.props.children, (child, i) => {
|
||||
const { children, disabled } = this.props;
|
||||
|
||||
return ReactAddons.Children.map(children, (child, i) => {
|
||||
if (child) {
|
||||
return React.cloneElement(child, {
|
||||
handleChange: this.handleChangeChild,
|
||||
ref: (ref) => {
|
||||
this._refs[child.props.name] = ref;
|
||||
if (child.props.name) {
|
||||
this._refs[child.props.name] = ref;
|
||||
}
|
||||
|
||||
// Since refs will be overwritten by this functions return statement,
|
||||
// we still want to be able to define refs for nested `Form` or `Property`
|
||||
@ -265,10 +268,11 @@ let Form = React.createClass({
|
||||
child.ref(ref);
|
||||
}
|
||||
},
|
||||
key: i,
|
||||
// We need this in order to make editable be overridable when setting it directly
|
||||
// on Property
|
||||
editable: child.props.overrideForm ? child.props.editable : !this.props.disabled
|
||||
editable: child.props.overrideForm ? child.props.editable : !disabled,
|
||||
handleChange: this.handleChangeChild,
|
||||
key: i
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -263,17 +263,13 @@ const Property = React.createClass({
|
||||
},
|
||||
|
||||
renderChildren(style) {
|
||||
const { checkboxLabel, children, editable, name } = this.props;
|
||||
|
||||
// Input's props should only be cloned and propagated down the tree,
|
||||
// if the component is actually being shown (!== 'expanded === false')
|
||||
if((this.state.expanded && this.props.checkboxLabel) || !this.props.checkboxLabel) {
|
||||
return ReactAddons.Children.map(this.props.children, (child) => {
|
||||
if ((this.state.expanded && checkboxLabel) || !checkboxLabel) {
|
||||
return ReactAddons.Children.map(children, (child) => {
|
||||
const childWithProps = React.cloneElement(child, {
|
||||
style,
|
||||
onChange: this.handleChange,
|
||||
onFocus: this.handleFocus,
|
||||
onBlur: this.handleBlur,
|
||||
setWarning: this.setWarning,
|
||||
disabled: !this.props.editable,
|
||||
ref: (ref) => {
|
||||
this._refs.input = ref;
|
||||
|
||||
@ -285,8 +281,14 @@ const Property = React.createClass({
|
||||
child.ref(ref);
|
||||
}
|
||||
},
|
||||
name: this.props.name,
|
||||
setExpanded: this.setExpanded
|
||||
name,
|
||||
style,
|
||||
disabled: !editable,
|
||||
onBlur: this.handleBlur,
|
||||
onChange: this.handleChange,
|
||||
onFocus: this.handleFocus,
|
||||
setExpanded: this.setExpanded,
|
||||
setWarning: this.setWarning
|
||||
});
|
||||
|
||||
return childWithProps;
|
||||
|
Loading…
Reference in New Issue
Block a user