From b7be3af21c25e8d50b93abf2028afda64f2a58f8 Mon Sep 17 00:00:00 2001 From: Dmitry Lyzo Date: Wed, 23 Aug 2023 23:58:07 +0300 Subject: [PATCH] Fix slider step Use the value of the `step` attribute if no keyboard steps are specified. (cherry picked from commit 7d27596d6b7545a4d48cc03e26b4f32a3729c591) --- src/elements/emby-slider/emby-slider.js | 29 +++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/elements/emby-slider/emby-slider.js b/src/elements/emby-slider/emby-slider.js index afd94909207..5e44fb03c67 100644 --- a/src/elements/emby-slider/emby-slider.js +++ b/src/elements/emby-slider/emby-slider.js @@ -19,6 +19,27 @@ if (Object.getOwnPropertyDescriptor && Object.defineProperty) { } } +/** + * Returns normalized slider step. + * + * @param {HTMLInputElement} range slider itself + * @param {number|undefined} step step + * @returns {number} normalized slider step. + */ +function normalizeSliderStep(range, step) { + if (step > 0) { + return step; + } + + step = parseFloat(range.step); + + if (step > 0) { + return step; + } + + return 1; +} + /** * Returns slider fraction corresponding to client position. * @@ -37,7 +58,7 @@ function mapClientToFraction(range, clientX) { // Snap to step const valueRange = range.max - range.min; if (range.step !== 'any' && valueRange !== 0) { - const step = (range.step || 1) / valueRange; + const step = normalizeSliderStep(range) / valueRange; fraction = Math.round(fraction / step) * step; } @@ -56,7 +77,7 @@ function mapFractionToValue(range, fraction) { // Snap to step if (range.step !== 'any') { - const step = range.step || 1; + const step = normalizeSliderStep(range); value = Math.round(value / step) * step; } @@ -455,13 +476,13 @@ function onKeyDown(e) { switch (keyboardnavigation.getKeyName(e)) { case 'ArrowLeft': case 'Left': - stepKeyboard(this, -this.keyboardStepDown || -1); + stepKeyboard(this, -normalizeSliderStep(this, this.keyboardStepDown)); e.preventDefault(); e.stopPropagation(); break; case 'ArrowRight': case 'Right': - stepKeyboard(this, this.keyboardStepUp || 1); + stepKeyboard(this, normalizeSliderStep(this, this.keyboardStepUp)); e.preventDefault(); e.stopPropagation(); break;