From 008694b670ea564a7c5f0bcefe4ba1ea1a91bc33 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sat, 28 Jun 2025 23:39:38 +0200 Subject: [PATCH] Fix number setting invalid value handling The component prevented invalid values from being inserted at all, which caused issues with changing values overall. --- .../core/components/settings/NumberSetting.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/modules/core/components/settings/NumberSetting.tsx b/src/modules/core/components/settings/NumberSetting.tsx index 3ab797f5..8f67fd06 100644 --- a/src/modules/core/components/settings/NumberSetting.tsx +++ b/src/modules/core/components/settings/NumberSetting.tsx @@ -25,7 +25,6 @@ import Slider from '@mui/material/Slider'; import DialogContentText from '@mui/material/DialogContentText'; import InfoIcon from '@mui/icons-material/Info'; import { SxProps, Theme } from '@mui/material/styles'; -import { coerceIn } from '@/lib/HelperFunctions.ts'; type BaseProps = { settingTitle: string; @@ -77,6 +76,9 @@ export const NumberSetting = ({ const [dialogValue, setDialogValue] = useState(value); const [originalValue, setOriginalValue] = useState(value); + const isInvalid = + (minValue !== undefined && minValue > dialogValue) || (maxValue !== undefined && maxValue < dialogValue); + const updateValue = useCallback( (newValue: number, persist: boolean) => { setDialogValue(newValue); @@ -169,10 +171,11 @@ export const NumberSetting = ({ autoFocus value={dialogValue} type="number" + error={isInvalid} + helperText={isInvalid ? t('global.error.label.invalid_input') : ''} onChange={(e) => { const newValue = Number(e.target.value); - const newValueCoerced = coerceIn(newValue, minValue ?? newValue, maxValue ?? newValue); - updateValue(newValueCoerced, false); + updateValue(newValue, false); }} slotProps={{ input: { @@ -204,7 +207,7 @@ export const NumberSetting = ({ -