material-ui-phone-number icon indicating copy to clipboard operation
material-ui-phone-number copied to clipboard

add typescript support for onChange method

Open Basanta-Kc opened this issue 3 years ago • 4 comments

The onChange method is providing us mobile number and country info on the first and second param but the type definition includes only one event param due to which the users are unable to access the second param and are getting this error image So in order to overcome this error, I have added the type definition for the onChange method as

  onChange: ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement> & ((mobileNumber: string, country: Country) => void);

and the type definition for the country (second param) as

type Country = {
  name: string;
  dialCode: string;
  countryCode: string;
}

After this, the user can access both params successfully without any ts errors image

Basanta-Kc avatar Jan 07 '22 13:01 Basanta-Kc

Why was this PR was not merged?

ghost avatar Jun 06 '22 08:06 ghost

@alexplumb looks like a great fix

ghost avatar Jun 06 '22 08:06 ghost

This package (https://github.com/viclafouch/mui-tel-input) handles this problem, supports both React 17 / 18

viclafouch avatar Jul 02 '22 12:07 viclafouch

Until this is merged you can bypass the typescript error by setting the parameter as nullable: onChange={(value, country?) => {}}

peteranderss0n avatar Aug 04 '22 13:08 peteranderss0n