facebook / react

The library for web and native user interfaces.
https://react.dev
MIT License
227.6k stars 46.43k forks source link

Bug: When input type=number, input 1-1 cannot trigger an onchange and cannot be set to an empty string #30459

Open jzz2649 opened 1 month ago

jzz2649 commented 1 month ago

React version: all

Steps To Reproduce

  1. Input 1-1
  2. Set the value to an empty string

Link to code example:

const Test = () => {
    const [value, setValue] = useState('')

    return <input type="number" value={value} onChange={e => {
        console.log(e.target.value)
        if (e.target.value === '') {
                // Triggered when inputting 1-
                setValue('')
        } else {
                setValue(e.target.value)
        }
    }} />
}

The current behavior

  1. Input 1-1 will not trigger an onchange
  2. setValue ('') will not reset 1-
  3. This seems to be a browser bug

The expected behavior

  1. Input 1-1 to trigger onchange
  2. setValue ('') reset 1-
jzz2649 commented 1 month ago

Yes @neehhaa06