Skip to content

Commit

Permalink
Fix: Check if the value from the input field fits into the step settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnitto committed Nov 26, 2024
1 parent 96e2884 commit aee37f3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
13 changes: 12 additions & 1 deletion Resources/Private/RangeEditor/Editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,18 @@ function Editor(props) {

useEffect(() => {
if (debouncedState != value) {
changeValue(debouncedState);
// Check if the value from the input field fits into the step settings
const { step, min } = options;
const number = parseFloat(debouncedState);
let addValue = step - ((number - min) % step);
if (addValue == 0 || addValue == step) {
addValue = 0;
}
if (addValue > step / 2) {
addValue = addValue - step;
}
const finalValue = Math.min(options.max, Math.max(options.min, number + addValue));
changeValue(finalValue);
}
}, [debouncedState]);

Expand Down
2 changes: 1 addition & 1 deletion Resources/Public/Plugin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit aee37f3

Please sign in to comment.