Open
Description
When country is switched to another country that has the same international prefix, say USA and Canada, then when you start typing the phone number, the flag switches back to the first one. This is due to this code in index.js
:
updateFlagAndFormatNumber(number, actionAfterSetState = null) {
const { allowZeroAfterCountryCode, initialCountry } = this.props;
let iso2 = initialCountry;
let phoneNumber = number;
if (number) {
if (phoneNumber[0] !== "+") phoneNumber = `+${phoneNumber}`;
phoneNumber = allowZeroAfterCountryCode
? phoneNumber
: this.possiblyEliminateZeroAfterCountryCode(phoneNumber);
iso2 = PhoneNumber.getCountryCodeOfNumber(phoneNumber);
}
this.setState({ iso2, formattedNumber: phoneNumber }, actionAfterSetState);
}
This in turn calls PhoneNumber.getCountryCodeOfNumber
from phoneNumber.js:
getCountryCodeOfNumber(number) {
const dialCode = this.getDialCode(number);
const numeric = this.getNumeric(dialCode);
const countryCode = Country.getCountryCodes()[numeric];
// countryCode[0] can be null -> get first element that is not null
if (countryCode) {
return _.first(countryCode.filter(iso2 => iso2));
}
return '';
}
You will notice that the first element (in this case US) gets returned. We should allow for overlapping prefixes.
Metadata
Metadata
Assignees
Labels
No labels