From f8402a221180ec48dcfd75717b0a055908891455 Mon Sep 17 00:00:00 2001 From: tophf Date: Sun, 2 Aug 2020 06:50:12 +0300 Subject: [PATCH] use mousewheel to change focused "input[type=number], select" (#1010) * use mousewheel to change focused "input[type=number], select" * revert 0f394fa8 (no longer needed) --- edit/source-editor.js | 3 --- js/dom.js | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/edit/source-editor.js b/edit/source-editor.js index c4d1c041..7119cfa5 100644 --- a/edit/source-editor.js +++ b/edit/source-editor.js @@ -350,9 +350,6 @@ function createSourceEditor({style, onTitleChanged}) { } function headerOnScroll({target, deltaY, deltaMode, shiftKey}) { - if (target.tagName === 'INPUT' && target.type === 'number') { - return; - } while ((target = target.parentElement)) { if (deltaY < 0 && target.scrollTop || deltaY > 0 && target.scrollTop + target.clientHeight < target.scrollHeight) { diff --git a/js/dom.js b/js/dom.js index 5b1d39b4..db9d9f0f 100644 --- a/js/dom.js +++ b/js/dom.js @@ -91,6 +91,21 @@ document.addEventListener('click', e => { e.preventDefault(); } }); +// update inputs on mousewheel when focused +document.addEventListener('wheel', event => { + const el = document.activeElement; + if (!el || el !== event.target && !el.contains(event.target)) { + return; + } + if (el.tagName === 'SELECT') { + el.selectedIndex = Math.max(0, Math.min(el.length - 1, el.selectedIndex + Math.sign(event.deltaY))); + event.preventDefault(); + } + event.stopImmediatePropagation(); +}, { + capture: true, + passive: false, +}); function onDOMready() { if (document.readyState !== 'loading') {