I have a number input field that sets the new value through the state when the user is typing. This works fine. If I however add decimals to it (toFixed), the cursor will jump to the end of the input after typing only one digit. This happens when I, for example, delete what is there and type something else. If I instead add a digit between the first one and the decimal point, the cursor does not jump. Has anyone experienced this before, and what was the solution?
Fiddle to show the problem: https://jsfiddle.net/Inverness/k04yvq1u/
constructor() {
super()
this.state = {
number: 1
}
this.handleInputChange = this.handleInputChange.bind(this)
}
handleInputChange(event) {
console.log(event.target.value)
this.setState({
number: event.target.value
})
}
render() {
return (
<div>
<input
type="number"
value={ parseFloat(this.state.number).toFixed(2) }
onChange={ this.handleInputChange }
/>
</div>
)
}