fix: SliderOptions from logic
This commit is contained in:
parent
a8be01c737
commit
a07b8014bd
@ -52,6 +52,7 @@ export default function SliderOptions({ totalIndex }: Props) {
|
|||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
onBlur={({ target }) => {
|
onBlur={({ target }) => {
|
||||||
|
const start = listQuestions[quizId][totalIndex].content.start;
|
||||||
const min = Number(target.value);
|
const min = Number(target.value);
|
||||||
const max = Number(
|
const max = Number(
|
||||||
listQuestions[quizId][totalIndex].content.range.split("—")[1]
|
listQuestions[quizId][totalIndex].content.range.split("—")[1]
|
||||||
@ -68,6 +69,15 @@ export default function SliderOptions({ totalIndex }: Props) {
|
|||||||
content: clonContent,
|
content: clonContent,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (start < min) {
|
||||||
|
updateQuestionsList(quizId, totalIndex, {
|
||||||
|
content: {
|
||||||
|
...listQuestions[quizId][totalIndex].content,
|
||||||
|
start: min,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Typography>—</Typography>
|
<Typography>—</Typography>
|
||||||
@ -88,10 +98,13 @@ export default function SliderOptions({ totalIndex }: Props) {
|
|||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
onBlur={({ target }) => {
|
onBlur={({ target }) => {
|
||||||
|
const start = listQuestions[quizId][totalIndex].content.start;
|
||||||
|
const step = listQuestions[quizId][totalIndex].content.step;
|
||||||
const min = Number(
|
const min = Number(
|
||||||
listQuestions[quizId][totalIndex].content.range.split("—")[0]
|
listQuestions[quizId][totalIndex].content.range.split("—")[0]
|
||||||
);
|
);
|
||||||
const max = Number(target.value);
|
const max = Number(target.value);
|
||||||
|
const range = max - min;
|
||||||
|
|
||||||
if (max <= min) {
|
if (max <= min) {
|
||||||
const clonContent = listQuestions[quizId][totalIndex].content;
|
const clonContent = listQuestions[quizId][totalIndex].content;
|
||||||
@ -104,6 +117,34 @@ export default function SliderOptions({ totalIndex }: Props) {
|
|||||||
content: clonContent,
|
content: clonContent,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (start > max) {
|
||||||
|
updateQuestionsList(quizId, totalIndex, {
|
||||||
|
content: {
|
||||||
|
...listQuestions[quizId][totalIndex].content,
|
||||||
|
start: max,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (step > max) {
|
||||||
|
updateQuestionsList(quizId, totalIndex, {
|
||||||
|
content: {
|
||||||
|
...listQuestions[quizId][totalIndex].content,
|
||||||
|
step: max,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (range % step) {
|
||||||
|
setStepError(
|
||||||
|
`Шаг должен делить без остатка диапазон ${max} - ${min} = ${
|
||||||
|
max - min
|
||||||
|
}`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
setStepError("");
|
||||||
|
}
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
@ -120,7 +161,12 @@ export default function SliderOptions({ totalIndex }: Props) {
|
|||||||
<Typography>Начальное значение</Typography>
|
<Typography>Начальное значение</Typography>
|
||||||
<CustomNumberField
|
<CustomNumberField
|
||||||
placeholder={"50"}
|
placeholder={"50"}
|
||||||
min={0}
|
min={Number(
|
||||||
|
listQuestions[quizId][totalIndex].content.range.split("—")[0]
|
||||||
|
)}
|
||||||
|
max={Number(
|
||||||
|
listQuestions[quizId][totalIndex].content.range.split("—")[1]
|
||||||
|
)}
|
||||||
value={String(listQuestions[quizId][totalIndex].content.start)}
|
value={String(listQuestions[quizId][totalIndex].content.start)}
|
||||||
onChange={({ target }) => {
|
onChange={({ target }) => {
|
||||||
const clonContent = listQuestions[quizId][totalIndex].content;
|
const clonContent = listQuestions[quizId][totalIndex].content;
|
||||||
@ -129,21 +175,6 @@ export default function SliderOptions({ totalIndex }: Props) {
|
|||||||
content: clonContent,
|
content: clonContent,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
onBlur={({ target }) => {
|
|
||||||
const start = Number(target.value);
|
|
||||||
const min = Number(
|
|
||||||
listQuestions[quizId][totalIndex].content.range.split("—")[0]
|
|
||||||
);
|
|
||||||
|
|
||||||
if (start < min) {
|
|
||||||
updateQuestionsList(quizId, totalIndex, {
|
|
||||||
content: {
|
|
||||||
...listQuestions[quizId][totalIndex].content,
|
|
||||||
start: min,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
<Box sx={{ width: "100%" }}>
|
<Box sx={{ width: "100%" }}>
|
||||||
|
@ -30,16 +30,28 @@ export default function CustomNumberField({
|
|||||||
const inputValue = event.target.value;
|
const inputValue = event.target.value;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
Number(inputValue) >= min &&
|
inputValue === "" ||
|
||||||
Number(inputValue) <= max &&
|
inputValue.match(/^\d*$/) ||
|
||||||
(inputValue === "" ||
|
(inputValue[0] === "-" && inputValue.slice(1).match(/^\d*$/))
|
||||||
inputValue.match(/^\d*$/) ||
|
|
||||||
(inputValue[0] === "-" && inputValue.slice(1).match(/^\d*$/)))
|
|
||||||
) {
|
) {
|
||||||
onChange?.({ ...event, target: { ...event.target, value: inputValue } });
|
onChange?.({ ...event, target: { ...event.target, value: inputValue } });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onInputBlur = (event: FocusEvent<HTMLInputElement>) => {
|
||||||
|
const inputValue = event.target.value;
|
||||||
|
|
||||||
|
if (Number(inputValue) < min) {
|
||||||
|
onChange?.({ ...event, target: { ...event.target, value: String(min) } });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Number(inputValue) > max) {
|
||||||
|
onChange?.({ ...event, target: { ...event.target, value: String(max) } });
|
||||||
|
}
|
||||||
|
|
||||||
|
onBlur?.(event);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CustomTextField
|
<CustomTextField
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
@ -47,7 +59,7 @@ export default function CustomNumberField({
|
|||||||
error={error}
|
error={error}
|
||||||
onChange={onInputChange}
|
onChange={onInputChange}
|
||||||
onKeyDown={onKeyDown}
|
onKeyDown={onKeyDown}
|
||||||
onBlur={onBlur}
|
onBlur={onInputBlur}
|
||||||
value={value}
|
value={value}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user