From 7b2d8588aff434c7d6ade20734b78655e0ef13c7 Mon Sep 17 00:00:00 2001 From: Clemens Solar Date: Sun, 21 Jan 2024 01:45:49 +0100 Subject: [PATCH] fix: checkbox uses different field for value --- src/components/Customizer.tsx | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/components/Customizer.tsx b/src/components/Customizer.tsx index 2591d35..6aeae36 100644 --- a/src/components/Customizer.tsx +++ b/src/components/Customizer.tsx @@ -16,20 +16,19 @@ type Props = { }; export default function Customizer({ parameters, onChange }: Props) { - const handleParameterChange = ( - event: React.ChangeEvent - ) => { - const newParameters = parameters.map((parameter) => { - if (parameter.name === event.target.name) { - return { - ...parameter, - value: event.target.value, - }; - } - return parameter; - }); - onChange(newParameters); - }; + const handleParameterChange = + (isCheckbox) => (event: React.ChangeEvent) => { + const newParameters = parameters.map((parameter) => { + if (parameter.name === event.target.name) { + return { + ...parameter, + value: isCheckbox ? event.target.checked : event.target.value, + }; + } + return parameter; + }); + onChange(newParameters); + }; // Group parameters const groups = useMemo( @@ -66,7 +65,7 @@ export default function Customizer({ parameters, onChange }: Props) { type={parameter.type} key={parameter.name} name={parameter.name} - onChange={handleParameterChange} + onChange={handleParameterChange(false)} value={parameter.value} sx={{ mt: 2, p: 1 }} /> @@ -78,7 +77,7 @@ export default function Customizer({ parameters, onChange }: Props) { control={ }