Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slider step #4758

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/elements/emby-slider/emby-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@ import '../emby-input/emby-input';
}
}

/**
* 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;
thornbill marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Returns slider fraction corresponding to client position.
*
Expand All @@ -35,7 +56,7 @@ import '../emby-input/emby-input';
// 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;
}

Expand All @@ -54,7 +75,7 @@ import '../emby-input/emby-input';

// Snap to step
if (range.step !== 'any') {
const step = range.step || 1;
const step = normalizeSliderStep(range);
value = Math.round(value / step) * step;
}

Expand Down Expand Up @@ -377,13 +398,13 @@ import '../emby-input/emby-input';
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;
Expand Down