[TextField] How to prevent mousewheel in input of type number?
See original GitHub issueProblem description
Scrolling in a number field changes the values. In all the applications I have built so far people have asked me to prevent this behaviour because it sometimes causes corrupted data.
See also https://stackoverflow.com/questions/9712295/disable-scrolling-on-input-type-number/38589039#38589039
Steps to reproduce
Build a TextField of type number. Set focus into it. Scroll with your mousewheel.
Versions
This happens in all browsers in input elements, as far as I know.
Workaround
I have tried this:
document.addEventListener('mousewheel', function(event) {
if (window.document.activeElement.type === 'number') {
event.preventDefault()
}
})
But it only seems to work sometimes. No Idea why it only works inconsistently.
Request
Now I see that changing standard behaviour would not be good. But adding this as an option would be very nice.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:20 (6 by maintainers)
Top Results From Across the Web
Disable scrolling on `<input type=number>` - Stack Overflow
Prevent the default behavior of the mousewheel event on input-number elements like suggested by others (calling "blur()" would normally not ...
Read more >How do I prevent the mousewheel from incrementing and ...
$('input[type=number]').on('wheel', function(e){ return false; }); Maybe you need to adapt it, I can't reproduce that behavior.
Read more >How to disable scroll to change number in <input type ...
How to disable scroll to change number in <input type=”number”> field using JavaScript/jQuery? · Select the element. · Add an event to that ......
Read more >Disable Number Input Spinner & Scroll - CodePen
Adding Classes. In CodePen, whatever you write in the HTML editor is what goes within the <body> tags in a basic HTML5 template....
Read more >Disable scroll on input type number - Javascript - AdnanTech
target object. All input fields in HTML5 have a function named “blur()” which removes the focus from that input field. Calling this function ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
onWheel={event => event.target.blur()}
works, usingonWheel={event => event.currentTarget.blur()}
does not workWorks for me, thanks. A little bit of modification for typescript