PhoneInput: add some helpful comments

update-emoji-mart^2
Alex Gleason 2022-07-13 19:50:07 -05:00
rodzic efad8e0e67
commit 99c67916dd
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
1 zmienionych plików z 4 dodań i 0 usunięć

Wyświetl plik

@ -29,6 +29,8 @@ const PhoneInput: React.FC<IPhoneInput> = (props) => {
const asYouType = new AsYouType({ defaultCallingCode: countryCode });
const formatted = asYouType.input(target.value);
// If the new value is the same as before, we might be backspacing,
// so use the actual event value instead of the formatted value.
if (formatted === nationalNumber && target.value !== nationalNumber) {
setNationalNumber(target.value);
} else {
@ -43,6 +45,8 @@ const PhoneInput: React.FC<IPhoneInput> = (props) => {
const opts = { defaultCallingCode: countryCode, extract: false } as any;
const result = parsePhoneNumber(nationalNumber, opts);
// Throw if the number is invalid, but catch it below.
// We'll only ever call `onChange` with a valid E164 string or `undefined`.
if (!result.isPossible()) {
throw result;
}