From 2cd86137af55bd5927b78badfbe96ef13eb8b8d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Soryn=20B=C3=A4chli?= Date: Mon, 27 Feb 2023 12:13:06 +0100 Subject: [PATCH] Fixed number inputs being janky --- .../components/NewFarm/BasicInfoTab.tsx | 18 +++++------- .../components/NewFarm/ConditionsTab.tsx | 8 +++++- src/renderer/components/Settings/Setting.tsx | 1 + .../components/global/Inputs/NumberInput.tsx | 28 +++++++++---------- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/renderer/components/NewFarm/BasicInfoTab.tsx b/src/renderer/components/NewFarm/BasicInfoTab.tsx index d13259d..0b22d06 100644 --- a/src/renderer/components/NewFarm/BasicInfoTab.tsx +++ b/src/renderer/components/NewFarm/BasicInfoTab.tsx @@ -46,18 +46,13 @@ export default function BasicInfoTab({ data, onChange }: Props) { /> select.value === conditionsInfo.type + )?.display ?? '' + } fullWidth options={api.selections.FarmConditionSelect} onChange={(changed) => @@ -48,6 +52,7 @@ export default function ConditionsTab({ data, onChange }: Props) { (value); useEffect(() => { - if (value < 0) setInputValue(0); - - if (value < min) { - setInputValue(min); - } else if (value > max) { - setInputValue(max); - } else { - onChange(inputValue); - } + onChange(inputValue); }, [inputValue]); return ( -
+
{label && (
{label} @@ -77,12 +67,20 @@ export default function NumberInput({ 'hover:bg-pepper-800 focus:bg-pepper-800': !disabled } )} + type="number" disabled={disabled} value={value} - type="number" - onInput={(event) => { - setInputValue(parseInt(event.currentTarget.value)); + onChange={(event) => { + const { value, min, max } = event.target; + const adjustedValue = Math.max( + Number(min), + Math.min(Number(max), Number(value)) + ); + + setInputValue(adjustedValue); }} + min={min} + max={max} /> {withButtons && (