Skip to content

Commit

Permalink
fix: update useInput and remove unnecessary fake js events
Browse files Browse the repository at this point in the history
  • Loading branch information
jongomez committed Oct 4, 2023
1 parent c00b833 commit b9217ce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
16 changes: 0 additions & 16 deletions packages/lsd-react/src/components/NumberInput/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,12 @@ export const NumberInput: React.FC<NumberInputProps> & {
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 (
Expand Down
16 changes: 10 additions & 6 deletions packages/lsd-react/src/utils/useInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ export const useInput = <T extends InputValueType = InputValueType>(
: 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)
}

Expand Down

0 comments on commit b9217ce

Please sign in to comment.