From 85cef2945daddcdad326f027e733e3362f4b7668 Mon Sep 17 00:00:00 2001 From: Lukas Martinelli Date: Wed, 4 Jan 2017 12:06:55 +0100 Subject: [PATCH] StringInput triggers change on out of focus #46 --- src/components/inputs/StringInput.jsx | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/components/inputs/StringInput.jsx b/src/components/inputs/StringInput.jsx index 6d8a60e..b7f661f 100644 --- a/src/components/inputs/StringInput.jsx +++ b/src/components/inputs/StringInput.jsx @@ -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 this.props.onChange(e.target.value)} + onChange={e => this.changeValue(e.target.value)} + onBlur={() => this.props.onChange(this.state.value)} /> } }