catamphetamine / react-phone-number-input

React component for international phone number input
http://catamphetamine.gitlab.io/react-phone-number-input/
MIT License
925 stars 194 forks source link

Bug? value is prefixed with country code if the input field value changed instead of being replaced. #301

Closed ahmedelgabri closed 4 years ago

ahmedelgabri commented 4 years ago

Here is a reproduction to this issue https://codesandbox.io/s/tender-haze-qzjhw

Steps to reproduce the issue:

  1. Manualluy edit the input field, can be as simple as removing the last number & adding it again
  2. Change the country
  3. Bug?: Observe the output, the country code is added to the number instead of replacing it.

Now do the same but without step 1 & you will see the difference in the value that gets outputted.

catamphetamine commented 4 years ago

Released react-phone-number-input@2.5.0 with the fix: the phone number is now being cleared in such cases (unless the country being switched to has the same "country calling code" as the currently input international phone number; for example, when switching US -> Canada). Updated the demo.