Merge remote-tracking branch 'upstream/master' into feature/add-range-slider

This commit is contained in:
orangemug
2019-05-20 10:20:55 +01:00
9 changed files with 224 additions and 157 deletions

View File

@@ -19,20 +19,28 @@ class NumberInput extends React.Component {
constructor(props) {
super(props)
this.state = {
value: props.value
editing: false,
value: props.value,
}
}
static getDerivedStateFromProps(props, state) {
if (!state.editing) {
return {
value: props.value
};
}
}
changeValue(newValue) {
this.setState({editing: true});
const value = parseFloat(newValue)
const hasChanged = this.state.value !== value
if(this.isValid(value) && hasChanged) {
this.props.onChange(value)
this.setState({ value: value })
} else {
this.setState({ value: newValue })
}
this.setState({ value: newValue })
}
isValid(v) {
@@ -53,6 +61,7 @@ class NumberInput extends React.Component {
}
resetValue = () => {
this.setState({editing: false});
// Reset explicitly to default value if value has been cleared
if(this.state.value === "") {
return this.changeValue(this.props.default)