From 85d05cd6fefd134fbf38c34c033f2744b7629335 Mon Sep 17 00:00:00 2001 From: jongomez Date: Wed, 4 Oct 2023 16:16:54 +0100 Subject: [PATCH] fix: update useInput and remove unnecessary fake js events --- .../src/components/NumberInput/NumberInput.tsx | 16 ---------------- packages/lsd-react/src/utils/useInput.ts | 16 ++++++++++------ 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/packages/lsd-react/src/components/NumberInput/NumberInput.tsx b/packages/lsd-react/src/components/NumberInput/NumberInput.tsx index 86d42fc..19da8e9 100644 --- a/packages/lsd-react/src/components/NumberInput/NumberInput.tsx +++ b/packages/lsd-react/src/components/NumberInput/NumberInput.tsx @@ -59,28 +59,12 @@ export const NumberInput: React.FC & { if (disabled) return const newValue = Math.min(max, Number(input.value || '0') + step) input.setValue(newValue.toString()) - - const fakeEvent = { - target: { value: newValue.toString() }, - } - - if (onChange) { - input.onChange(fakeEvent as any) - } } const handleDecrement = () => { if (disabled) return const newValue = Math.max(min, Number(input.value || '0') - step) input.setValue(newValue.toString()) - - const fakeEvent = { - target: { value: newValue.toString() }, - } - - if (onChange) { - input.onChange(fakeEvent as any) - } } return ( diff --git a/packages/lsd-react/src/utils/useInput.ts b/packages/lsd-react/src/utils/useInput.ts index 0e8f1d0..fa60220 100644 --- a/packages/lsd-react/src/utils/useInput.ts +++ b/packages/lsd-react/src/utils/useInput.ts @@ -28,12 +28,16 @@ export const useInput = ( : value.toString().length > 0 const onChange: InputOnChangeType = (event) => { - const type = event.target.type - const value = - event.target[ - type === 'checkbox' || type === 'radio' ? 'checked' : 'value' - ] - if (uncontrolled) return setValue(value as T) + if (uncontrolled) { + const type = event.target.type + const value = + event.target[ + type === 'checkbox' || type === 'radio' ? 'checked' : 'value' + ] + + setValue(value as T) + } + props.onChange && props.onChange(event) }