Skip to content

Instantly share code, notes, and snippets.

@matsubo
Created November 27, 2023 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matsubo/537aaecfbfd5389794da22f273afa01b to your computer and use it in GitHub Desktop.
Save matsubo/537aaecfbfd5389794da22f273afa01b to your computer and use it in GitHub Desktop.
Disable wheel on <input type="number"> to prevent un-intended value change.
import { disableWheel } from './disable-wheel.js';
window.addEventListener('load', function () {
disableWheel('input[type="number"]')
}, false);
/**
* 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