vlad-ignatov / react-numeric-input

Numeric input component for react
MIT License
280 stars 104 forks source link

Unable to enter minus "-" sign manually when there is a callback method in onChange() #122

Open mpeng opened 4 years ago

mpeng commented 4 years ago

Below is my code. Once the this.props.callbackFromParent(a); is added, it won't take "-" sign if I don't change the default value from "0.0" to something like "2.0" first. However if I comment out this.props.callbackFromParent(a); then I am able to enter "-" before "0.0", without any issues.

I just could not figure out how the callback method can cause the issue.

  test = (a) => {
       console.log(a);
       // ToDo Why with below line, the minus "-" sign can not be entered.**
       this.props.callbackFromParent(a);
  }

  render() {
    const { o } = this.state;

    return (
    <NumericInput
        value={o}
        format={o => o}
        onChange={this.test}
        precision={this.props.precision}
        size={8}
        step={this.props.step}
        mobile={false}
        min={this.props.min}
        max={this.props.max}

Here is the version I am using: "react-numeric-input": "^2.2.3

This is an important requirement for my app. My users often want to enter a negative number manually using keyboard without using arrows first.

Please help when you can,

Thanks