Skip to content

Commit

Permalink
feat(input): makes Input more extensible
Browse files Browse the repository at this point in the history
  • Loading branch information
aviemet committed May 3, 2024
1 parent f21f779 commit 406e6c6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Inputs/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,28 @@ interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
}

const Input = React.forwardRef<HTMLInputElement, InputProps>((
{ name, component = 'input', model, ...props },
{ name, component = 'input', model, onChange, ...props },
ref,
) => {
const { inputName, inputId, value, setValue } = useInertiaInput({ name, model })

const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if(onChange) {
onChange(e)
return
}

setValue(e.target.value)
}

const Element = component

return (
<Element
name={ inputName }
id={ inputId }
value={ value }
onChange={ (e: React.ChangeEvent<HTMLInputElement>) => setValue(e.target.value) }
onChange={ handleChange }
ref={ ref }
{ ...props }
/>
Expand Down

0 comments on commit 406e6c6

Please sign in to comment.