While bored and scrolling through videos, I came across a video:
So I decided to try it myself and indeed found this issue to be true. I also tested some of the fixes suggested by Xiaoshan and they did fix the problem. However, during my testing, I accidentally discovered that when typing in Chinese, pressing the ⬆️ or ⬇️ keys on the keyboard would modify the value of the input:number
text box. I realized that this behavior is not what users would expect, and the value should not change in this case. So I attempted to fix this issue. Below is an example of my fix code:
The main methods used to fix this issue are:
- Listening for keyboard events and blocking the default behavior at the appropriate time.
- Checking if the user input is a non-numeric value.
- Note that
event.data
ande.target.value
in theinput
event are different. One represents the current input value, while the other represents the value in the input box.
- Note that
This issue exists in native browsers and is not related to any framework or other factors.
During my testing, I used Chrome version 115.0.5790.114 on MacOS 13.5 (22G74).