mirror of https://github.com/acid-info/lsd.git
fix: update useInput and remove unnecessary fake js events
This commit is contained in:
parent
86125f73fd
commit
85d05cd6fe
|
@ -59,28 +59,12 @@ export const NumberInput: React.FC<NumberInputProps> & {
|
||||||
if (disabled) return
|
if (disabled) return
|
||||||
const newValue = Math.min(max, Number(input.value || '0') + step)
|
const newValue = Math.min(max, Number(input.value || '0') + step)
|
||||||
input.setValue(newValue.toString())
|
input.setValue(newValue.toString())
|
||||||
|
|
||||||
const fakeEvent = {
|
|
||||||
target: { value: newValue.toString() },
|
|
||||||
}
|
|
||||||
|
|
||||||
if (onChange) {
|
|
||||||
input.onChange(fakeEvent as any)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleDecrement = () => {
|
const handleDecrement = () => {
|
||||||
if (disabled) return
|
if (disabled) return
|
||||||
const newValue = Math.max(min, Number(input.value || '0') - step)
|
const newValue = Math.max(min, Number(input.value || '0') - step)
|
||||||
input.setValue(newValue.toString())
|
input.setValue(newValue.toString())
|
||||||
|
|
||||||
const fakeEvent = {
|
|
||||||
target: { value: newValue.toString() },
|
|
||||||
}
|
|
||||||
|
|
||||||
if (onChange) {
|
|
||||||
input.onChange(fakeEvent as any)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -28,12 +28,16 @@ export const useInput = <T extends InputValueType = InputValueType>(
|
||||||
: value.toString().length > 0
|
: value.toString().length > 0
|
||||||
|
|
||||||
const onChange: InputOnChangeType = (event) => {
|
const onChange: InputOnChangeType = (event) => {
|
||||||
|
if (uncontrolled) {
|
||||||
const type = event.target.type
|
const type = event.target.type
|
||||||
const value =
|
const value =
|
||||||
event.target[
|
event.target[
|
||||||
type === 'checkbox' || type === 'radio' ? 'checked' : 'value'
|
type === 'checkbox' || type === 'radio' ? 'checked' : 'value'
|
||||||
]
|
]
|
||||||
if (uncontrolled) return setValue(value as T)
|
|
||||||
|
setValue(value as T)
|
||||||
|
}
|
||||||
|
|
||||||
props.onChange && props.onChange(event)
|
props.onChange && props.onChange(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue