Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usePhoneInput#onChange to return ChangeEvent #207

Open
wingsofovnia opened this issue Sep 1, 2024 · 0 comments
Open

usePhoneInput#onChange to return ChangeEvent #207

wingsofovnia opened this issue Sep 1, 2024 · 0 comments

Comments

@wingsofovnia
Copy link

wingsofovnia commented Sep 1, 2024

Currently, usePhoneInput takes onChange callback that accepts parsed params (data: { phone: string; inputValue: string; country: ParsedCountry })).

It is however helpful to keep access to native event. For example, when wrapping an existing Input component already having an onChange callback, which accepts a native event, like Chakra UI:

import { InputProps as ChakraInputProps } from '@chakra-ui/react'

export const TelInput = forwardRef<HTMLInputElement, ChakraInputProps>(function TelInput(
  {
    defaultValue,
    onChange: userOnChange,
    ...inputProps
  },
  userRef,
) {
  const phoneInput = usePhoneInput({
    value: defaultValue?.toString(),
    onChange: (data) => {
      userOnChange?.(data.phone) // TS2345: Argument of type string is not assignable to parameter of type ChangeEvent<HTMLInputElement>
    },
  })
// ...
})

It would be great to extend data callback argument with an event field, which will have event propagated from handlePhoneValueChange.

Meanwhile, this works for selected use cases:

onChange: (data) => {
  userOnChange?.({ target: { value: data.phone } } as ChangeEvent<HTMLInputElement>)
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant