catamphetamine / react-phone-number-input

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

Having to select country twice #347

Closed robbileifss closed 3 years ago

robbileifss commented 4 years ago

Hi,

I have an issue, maybe it's something I've missed or wrongly setup. But I can't find out. When going back in my application to the page where I selected the country from the phoneinput control. Wanting to change the country, I have to select it twice in order for it to stick. See the attached gif.

phoniinput

robbileifss commented 4 years ago

@catamphetamine any idea if this is the framework or just my code?

catamphetamine commented 4 years ago

@robbileifss Hi. Yeah, I haven't looked into the issue yet. I can look at it some time later, but not anytime soon. Maybe in a month or two.

arikimolloy commented 3 years ago

@robbileifss I was seeing the same issue.

This is what my code looked like: <PhoneInput value={value == null ? "" : `${value.rawInput}`} .......

The fix for me was to instead of setting value to an empty string, set it to "undefined": <PhoneInput value={value == null ? "undefined" : `${value.rawInput}`} ......

catamphetamine commented 3 years ago

I'll add this note in the README since people are periodically expecting it to handle empty strings.

Note: Don't pass an empty string value, pass undefined instead. Same's true for the value argument of onChange — when value is empty, it is undefined, not an empty string.