kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
PhoneInput: add some helpful comments
rodzic
efad8e0e67
commit
99c67916dd
|
@ -29,6 +29,8 @@ const PhoneInput: React.FC<IPhoneInput> = (props) => {
|
||||||
const asYouType = new AsYouType({ defaultCallingCode: countryCode });
|
const asYouType = new AsYouType({ defaultCallingCode: countryCode });
|
||||||
const formatted = asYouType.input(target.value);
|
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) {
|
if (formatted === nationalNumber && target.value !== nationalNumber) {
|
||||||
setNationalNumber(target.value);
|
setNationalNumber(target.value);
|
||||||
} else {
|
} else {
|
||||||
|
@ -43,6 +45,8 @@ const PhoneInput: React.FC<IPhoneInput> = (props) => {
|
||||||
const opts = { defaultCallingCode: countryCode, extract: false } as any;
|
const opts = { defaultCallingCode: countryCode, extract: false } as any;
|
||||||
const result = parsePhoneNumber(nationalNumber, opts);
|
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()) {
|
if (!result.isPossible()) {
|
||||||
throw result;
|
throw result;
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue