Created
November 27, 2023 07:40
-
-
Save matsubo/537aaecfbfd5389794da22f273afa01b to your computer and use it in GitHub Desktop.
Disable wheel on <input type="number"> to prevent un-intended value change.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { disableWheel } from './disable-wheel.js'; | |
window.addEventListener('load', function () { | |
disableWheel('input[type="number"]') | |
}, false); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Disable changing value using mouse wheel | |
*/ | |
export function disableWheel(selector) { | |
document.querySelectorAll(selector).forEach(input => { | |
input.addEventListener('wheel', event => event.preventDefault(), { passive: false }); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment