StringInput triggers change on out of focus #46

This commit is contained in:
Lukas Martinelli 2017-01-04 12:06:55 +01:00
parent a1dfeca6e0
commit 85cef2945d

View file

@ -9,15 +9,32 @@ class StringInput extends React.Component {
onChange: React.PropTypes.func,
}
constructor(props) {
super(props)
this.state = {
value: props.value
}
}
changeValue(newValue) {
//TODO: In feature we can try to do validation here as well
this.setState({ value: newValue })
}
componentWillReceiveProps(nextProps) {
this.setState({ value: nextProps.value })
}
render() {
return <input
style={{
...input.input,
...this.props.style
}}
value={this.props.value}
value={this.state.value}
placeholder={this.props.default}
onChange={e => this.props.onChange(e.target.value)}
onChange={e => this.changeValue(e.target.value)}
onBlur={() => this.props.onChange(this.state.value)}
/>
}
}