fix: step

This commit is contained in:
IlyaDoronin 2023-12-25 19:16:04 +03:00
parent 3584d32820
commit 8430ff9992
2 changed files with 12 additions and 9 deletions

@ -219,8 +219,10 @@ export default function SliderOptions({ question }: Props) {
});
}}
onBlur={({ target }) => {
const min = Number(question.content.range.split("—")[0]);
const max = Number(question.content.range.split("—")[1]);
const step = Number(target.value);
const range = max - min;
if (step > max) {
updateQuestion(question.id, (question) => {
@ -229,6 +231,14 @@ export default function SliderOptions({ question }: Props) {
question.content.step = max;
});
}
if (range % step) {
updateQuestion(question.id, (question) => {
if (question.type !== "number") return;
question.content.step = 1;
});
}
}}
/>
</Box>

@ -43,14 +43,7 @@ export const Number = ({ currentQuestion }: NumberProps) => {
const min = window.Number(currentQuestion.content.range.split("—")[0]);
const max = window.Number(currentQuestion.content.range.split("—")[1]);
const step = currentQuestion.content.step;
const sliderValue =
answer ||
(currentQuestion.content.start < min || currentQuestion.content.start > max
? min
: currentQuestion.content.start) +
"—" +
max;
const sliderValue = answer || currentQuestion.content.start + "—" + max;
useEffect(() => {
if (answer) {
@ -86,7 +79,7 @@ export const Number = ({ currentQuestion }: NumberProps) => {
}
min={min}
max={max}
step={(max - min) % step ? 1 : step}
step={currentQuestion.content.step || 1}
onChange={(_, value) => {
const range = String(value).replace(",", "—");
updateAnswer(currentQuestion.content.id, range);