intl-tel-input 27.1.2 → 27.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +2 -2
- package/angular/README.md +8 -0
- package/angular/dist/IntlTelInput.d.ts +13 -1
- package/angular/dist/IntlTelInput.js +238 -186
- package/angular/dist/IntlTelInputWithUtils.js +238 -186
- package/dist/js/data.js +1 -1
- package/dist/js/data.min.js +1 -1
- package/dist/js/intlTelInput.js +204 -184
- package/dist/js/intlTelInput.min.js +9 -9
- package/dist/js/intlTelInput.mjs +203 -183
- package/dist/js/intlTelInputWithUtils.js +204 -184
- package/dist/js/intlTelInputWithUtils.min.js +7 -7
- package/dist/js/intlTelInputWithUtils.mjs +203 -183
- package/package.json +1 -1
- package/react/README.md +8 -0
- package/react/dist/IntlTelInput.d.ts +5 -0
- package/react/dist/IntlTelInput.js +246 -188
- package/react/dist/IntlTelInputWithUtils.js +246 -188
- package/svelte/README.md +9 -0
- package/svelte/src/IntlTelInput.svelte +49 -7
- package/svelte/src/IntlTelInput.svelte.d.ts +6 -0
- package/vue/README.md +9 -0
- package/vue/dist/{IntlTelInput-6eM889WB.js → IntlTelInput-DTtMkd4-.js} +338 -309
- package/vue/dist/IntlTelInput.js +1 -1
- package/vue/dist/IntlTelInput.vue.d.ts +19 -11
- package/vue/dist/IntlTelInputWithUtils.js +1 -1
|
@@ -2991,7 +2991,7 @@ var UI = class _UI {
|
|
|
2991
2991
|
this.#selectedCountryEl.focus();
|
|
2992
2992
|
}
|
|
2993
2993
|
}
|
|
2994
|
-
if (!this.#options.countrySearch && REGEX.HIDDEN_SEARCH_CHAR.test(e.key)) {
|
|
2994
|
+
if (!this.#options.countrySearch && e.target !== this.telInputEl && REGEX.HIDDEN_SEARCH_CHAR.test(e.key)) {
|
|
2995
2995
|
e.stopPropagation();
|
|
2996
2996
|
if (queryTimer) {
|
|
2997
2997
|
clearTimeout(queryTimer);
|
|
@@ -3513,6 +3513,8 @@ var Iti = class _Iti {
|
|
|
3513
3513
|
#isActive = true;
|
|
3514
3514
|
#abortController;
|
|
3515
3515
|
#numerals;
|
|
3516
|
+
//* Tracks whether the user has typed/pasted their own formatting chars, so AYT-formatting should back off.
|
|
3517
|
+
#userOverrideFormatting = false;
|
|
3516
3518
|
#autoCountryDeferred;
|
|
3517
3519
|
#utilsDeferred;
|
|
3518
3520
|
constructor(input, customOptions = {}) {
|
|
@@ -3702,176 +3704,211 @@ var Iti = class _Iti {
|
|
|
3702
3704
|
this.#bindKeydownListener();
|
|
3703
3705
|
this.#bindPasteListener();
|
|
3704
3706
|
}
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3707
|
+
//* Android workaround for handling plus when separateDialCode enabled (as impossible to handle with keydown/keyup, for which e.key always returns "Unidentified", see https://stackoverflow.com/q/59584061/217866)
|
|
3708
|
+
#handleAndroidPlusKey(inputValue) {
|
|
3709
|
+
this.#removeJustTypedChar(inputValue);
|
|
3710
|
+
this.#openDropdownWithPlus();
|
|
3711
|
+
}
|
|
3712
|
+
//* Android strictMode workaround: the keydown-based filter can't block these because e.key is "Unidentified" on Android virtual keyboards, so strip them here on input.
|
|
3713
|
+
#handleAndroidStrictReject(inputValue, rejectedInput) {
|
|
3714
|
+
const newCaretPos = this.#removeJustTypedChar(inputValue);
|
|
3715
|
+
this.#ui.telInputEl.setSelectionRange(newCaretPos, newCaretPos);
|
|
3716
|
+
this.#dispatchEvent(EVENTS.STRICT_REJECT, {
|
|
3717
|
+
source: "key",
|
|
3718
|
+
rejectedInput,
|
|
3719
|
+
reason: "invalid"
|
|
3720
|
+
});
|
|
3721
|
+
}
|
|
3722
|
+
//* Format the input value using libphonenumber's AYT formatter, preserving caret position (called after an input event).
|
|
3723
|
+
#formatAsYouType(inputValue, isDeleteForwards) {
|
|
3724
|
+
const currentCaretPos = this.#ui.telInputEl.selectionStart || 0;
|
|
3725
|
+
const valueBeforeCaret = inputValue.substring(0, currentCaretPos);
|
|
3726
|
+
const relevantCharsBeforeCaret = valueBeforeCaret.replace(
|
|
3727
|
+
REGEX.NON_PLUS_NUMERIC_GLOBAL,
|
|
3728
|
+
""
|
|
3729
|
+
).length;
|
|
3730
|
+
const fullNumber = this.#getFullNumber();
|
|
3731
|
+
const formattedValue = formatNumberAsYouType(
|
|
3732
|
+
fullNumber,
|
|
3733
|
+
inputValue,
|
|
3734
|
+
intlTelInput.utils,
|
|
3735
|
+
this.#selectedCountry,
|
|
3736
|
+
this.#options.separateDialCode
|
|
3737
|
+
);
|
|
3738
|
+
const newCaretPos = computeNewCaretPosition(
|
|
3739
|
+
relevantCharsBeforeCaret,
|
|
3740
|
+
formattedValue,
|
|
3741
|
+
currentCaretPos,
|
|
3742
|
+
isDeleteForwards
|
|
3743
|
+
);
|
|
3744
|
+
this.#setTelInputValue(formattedValue);
|
|
3745
|
+
this.#ui.telInputEl.setSelectionRange(newCaretPos, newCaretPos);
|
|
3746
|
+
}
|
|
3747
|
+
//* If separateDialCode AND typed dial code (e.g. from paste or autofill, or from typing a dial code when countrySearch disabled), then remove the typed dial code.
|
|
3748
|
+
//* Only strip when a full dial code is actually present — otherwise a lone typed "+" (or partial prefix) would get erased.
|
|
3749
|
+
#stripTypedDialCode(inputValue) {
|
|
3750
|
+
if (inputValue.startsWith("+") && this.#selectedCountry && this.#getDialCode(inputValue)) {
|
|
3751
|
+
const cleanNumber = stripSeparateDialCode(
|
|
3752
|
+
inputValue,
|
|
3753
|
+
true,
|
|
3754
|
+
true,
|
|
3755
|
+
this.#selectedCountry
|
|
3756
|
+
);
|
|
3757
|
+
this.#setTelInputValue(cleanNumber);
|
|
3716
3758
|
}
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
if (this.#isAndroid && e?.data === "+" && separateDialCode && allowDropdown && countrySearch) {
|
|
3723
|
-
this.#removeJustTypedChar(inputValue);
|
|
3724
|
-
this.#openDropdownWithPlus();
|
|
3725
|
-
return;
|
|
3726
|
-
}
|
|
3727
|
-
if (this.#isAndroid && strictMode && (e?.data === " " || e?.data === "-" || e?.data === ".")) {
|
|
3728
|
-
const newCaretPos = this.#removeJustTypedChar(inputValue);
|
|
3729
|
-
this.#ui.telInputEl.setSelectionRange(newCaretPos, newCaretPos);
|
|
3730
|
-
this.#dispatchEvent(EVENTS.STRICT_REJECT, {
|
|
3731
|
-
source: "key",
|
|
3732
|
-
rejectedInput: e.data,
|
|
3733
|
-
reason: "invalid"
|
|
3734
|
-
});
|
|
3735
|
-
return;
|
|
3736
|
-
}
|
|
3737
|
-
if (this.#updateCountryFromNumber(inputValue)) {
|
|
3738
|
-
this.#dispatchCountryChangeEvent();
|
|
3739
|
-
}
|
|
3740
|
-
const isFormattingChar = e?.data && REGEX.NON_PLUS_NUMERIC.test(e.data);
|
|
3741
|
-
const isPaste = e?.inputType === INPUT_TYPES.PASTE && inputValue;
|
|
3742
|
-
if (isFormattingChar || isPaste && !strictMode) {
|
|
3743
|
-
userOverrideFormatting = true;
|
|
3744
|
-
} else if (!REGEX.NON_PLUS_NUMERIC.test(inputValue)) {
|
|
3745
|
-
userOverrideFormatting = false;
|
|
3746
|
-
}
|
|
3747
|
-
const isSetNumber = e?.detail && e.detail["isSetNumber"];
|
|
3748
|
-
const isAscii = this.#numerals.isAscii();
|
|
3749
|
-
if (formatAsYouType && !userOverrideFormatting && !isSetNumber && isAscii) {
|
|
3750
|
-
const currentCaretPos = this.#ui.telInputEl.selectionStart || 0;
|
|
3751
|
-
const valueBeforeCaret = inputValue.substring(0, currentCaretPos);
|
|
3752
|
-
const relevantCharsBeforeCaret = valueBeforeCaret.replace(
|
|
3753
|
-
REGEX.NON_PLUS_NUMERIC_GLOBAL,
|
|
3754
|
-
""
|
|
3755
|
-
).length;
|
|
3756
|
-
const isDeleteForwards = e?.inputType === INPUT_TYPES.DELETE_FORWARD;
|
|
3757
|
-
const fullNumber = this.#getFullNumber();
|
|
3758
|
-
const formattedValue = formatNumberAsYouType(
|
|
3759
|
-
fullNumber,
|
|
3760
|
-
inputValue,
|
|
3761
|
-
intlTelInput.utils,
|
|
3762
|
-
this.#selectedCountry,
|
|
3763
|
-
separateDialCode
|
|
3764
|
-
);
|
|
3765
|
-
const newCaretPos = computeNewCaretPosition(
|
|
3766
|
-
relevantCharsBeforeCaret,
|
|
3767
|
-
formattedValue,
|
|
3768
|
-
currentCaretPos,
|
|
3769
|
-
isDeleteForwards
|
|
3770
|
-
);
|
|
3771
|
-
this.#setTelInputValue(formattedValue);
|
|
3772
|
-
this.#ui.telInputEl.setSelectionRange(newCaretPos, newCaretPos);
|
|
3773
|
-
}
|
|
3774
|
-
if (separateDialCode && inputValue.startsWith("+") && this.#selectedCountry?.dialCode) {
|
|
3775
|
-
const cleanNumber = stripSeparateDialCode(
|
|
3776
|
-
inputValue,
|
|
3777
|
-
true,
|
|
3778
|
-
separateDialCode,
|
|
3779
|
-
this.#selectedCountry
|
|
3780
|
-
);
|
|
3781
|
-
this.#setTelInputValue(cleanNumber);
|
|
3782
|
-
}
|
|
3783
|
-
};
|
|
3759
|
+
}
|
|
3760
|
+
#bindInputListener() {
|
|
3761
|
+
this.#userOverrideFormatting = REGEX.ALPHA_UNICODE.test(
|
|
3762
|
+
this.#getTelInputValue()
|
|
3763
|
+
);
|
|
3784
3764
|
this.#ui.telInputEl.addEventListener(
|
|
3785
3765
|
"input",
|
|
3786
|
-
handleInputEvent,
|
|
3766
|
+
this.#handleInputEvent,
|
|
3787
3767
|
{
|
|
3788
3768
|
signal: this.#abortController.signal
|
|
3789
3769
|
}
|
|
3790
3770
|
);
|
|
3791
3771
|
}
|
|
3772
|
+
//* On input event: (1) Update selected country, (2) Format-as-you-type.
|
|
3773
|
+
//* Note that this fires AFTER the input is updated.
|
|
3774
|
+
#handleInputEvent = (e) => {
|
|
3775
|
+
const { strictMode, formatAsYouType, separateDialCode, allowDropdown, countrySearch } = this.#options;
|
|
3776
|
+
const detail = e?.detail;
|
|
3777
|
+
if (detail?.["isCountryChange"]) {
|
|
3778
|
+
return;
|
|
3779
|
+
}
|
|
3780
|
+
const inputValue = this.#getTelInputValue();
|
|
3781
|
+
if (this.#isAndroid && e?.data === "+" && separateDialCode && allowDropdown && countrySearch) {
|
|
3782
|
+
this.#handleAndroidPlusKey(inputValue);
|
|
3783
|
+
return;
|
|
3784
|
+
}
|
|
3785
|
+
if (this.#isAndroid && strictMode && (e?.data === " " || e?.data === "-" || e?.data === ".")) {
|
|
3786
|
+
this.#handleAndroidStrictReject(inputValue, e.data);
|
|
3787
|
+
return;
|
|
3788
|
+
}
|
|
3789
|
+
if (this.#updateCountryFromNumber(inputValue)) {
|
|
3790
|
+
this.#dispatchCountryChangeEvent();
|
|
3791
|
+
}
|
|
3792
|
+
const isFormattingChar = e?.data && REGEX.NON_PLUS_NUMERIC.test(e.data);
|
|
3793
|
+
const isPaste = e?.inputType === INPUT_TYPES.PASTE && inputValue;
|
|
3794
|
+
if (isFormattingChar || isPaste && !strictMode) {
|
|
3795
|
+
this.#userOverrideFormatting = true;
|
|
3796
|
+
} else if (!REGEX.NON_PLUS_NUMERIC.test(inputValue)) {
|
|
3797
|
+
this.#userOverrideFormatting = false;
|
|
3798
|
+
}
|
|
3799
|
+
if (formatAsYouType && !this.#userOverrideFormatting && !detail?.["isSetNumber"] && this.#numerals.isAscii()) {
|
|
3800
|
+
this.#formatAsYouType(
|
|
3801
|
+
inputValue,
|
|
3802
|
+
e?.inputType === INPUT_TYPES.DELETE_FORWARD
|
|
3803
|
+
);
|
|
3804
|
+
}
|
|
3805
|
+
if (separateDialCode) {
|
|
3806
|
+
this.#stripTypedDialCode(inputValue);
|
|
3807
|
+
}
|
|
3808
|
+
};
|
|
3792
3809
|
#bindKeydownListener() {
|
|
3793
|
-
const { strictMode, separateDialCode
|
|
3810
|
+
const { strictMode, separateDialCode } = this.#options;
|
|
3794
3811
|
if (!strictMode && !separateDialCode) {
|
|
3795
3812
|
return;
|
|
3796
3813
|
}
|
|
3797
|
-
|
|
3798
|
-
if (!e.key || e.key.length !== 1 || e.altKey || e.ctrlKey || e.metaKey) {
|
|
3799
|
-
return;
|
|
3800
|
-
}
|
|
3801
|
-
if (separateDialCode && allowDropdown && countrySearch && e.key === "+") {
|
|
3802
|
-
e.preventDefault();
|
|
3803
|
-
this.#openDropdownWithPlus();
|
|
3804
|
-
return;
|
|
3805
|
-
}
|
|
3806
|
-
if (!strictMode) {
|
|
3807
|
-
return;
|
|
3808
|
-
}
|
|
3809
|
-
const inputValue = this.#getTelInputValue();
|
|
3810
|
-
const alreadyHasPlus = inputValue.startsWith("+");
|
|
3811
|
-
const isInitialPlus = !alreadyHasPlus && this.#ui.telInputEl.selectionStart === 0 && e.key === "+";
|
|
3812
|
-
const normalisedKey = this.#numerals.normalise(e.key);
|
|
3813
|
-
const isNumeric = /^[0-9]$/.test(normalisedKey);
|
|
3814
|
-
const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
|
|
3815
|
-
const input = this.#ui.telInputEl;
|
|
3816
|
-
const selStart = input.selectionStart;
|
|
3817
|
-
const selEnd = input.selectionEnd;
|
|
3818
|
-
const before = inputValue.slice(0, selStart ?? void 0);
|
|
3819
|
-
const after = inputValue.slice(selEnd ?? void 0);
|
|
3820
|
-
const newValue = before + normalisedKey + after;
|
|
3821
|
-
const newFullNumber = this.#buildFullNumber(newValue);
|
|
3822
|
-
let hasExceededMaxLength = false;
|
|
3823
|
-
if (intlTelInput.utils && this.#maxCoreNumberLength) {
|
|
3824
|
-
const coreNumber = intlTelInput.utils.getCoreNumber(
|
|
3825
|
-
newFullNumber,
|
|
3826
|
-
this.#selectedCountry?.iso2
|
|
3827
|
-
);
|
|
3828
|
-
hasExceededMaxLength = coreNumber.length > this.#maxCoreNumberLength;
|
|
3829
|
-
}
|
|
3830
|
-
const newCountry = this.#resolveCountryChangeFromNumber(newFullNumber);
|
|
3831
|
-
const isChangingDialCode = newCountry !== null;
|
|
3832
|
-
if (!isAllowedChar || hasExceededMaxLength && !isChangingDialCode && !isInitialPlus) {
|
|
3833
|
-
this.#dispatchEvent(EVENTS.STRICT_REJECT, {
|
|
3834
|
-
source: "key",
|
|
3835
|
-
rejectedInput: e.key,
|
|
3836
|
-
reason: !isAllowedChar ? "invalid" : "max-length"
|
|
3837
|
-
});
|
|
3838
|
-
e.preventDefault();
|
|
3839
|
-
}
|
|
3840
|
-
};
|
|
3841
|
-
this.#ui.telInputEl.addEventListener("keydown", handleKeydownEvent, {
|
|
3814
|
+
this.#ui.telInputEl.addEventListener("keydown", this.#handleKeydownEvent, {
|
|
3842
3815
|
signal: this.#abortController.signal
|
|
3843
3816
|
});
|
|
3844
3817
|
}
|
|
3818
|
+
//* On keydown event: (1) if strictMode then prevent invalid characters, (2) if separateDialCode then handle plus key
|
|
3819
|
+
//* Note that this fires BEFORE the input is updated.
|
|
3820
|
+
#handleKeydownEvent = (e) => {
|
|
3821
|
+
const { strictMode, separateDialCode, allowDropdown, countrySearch } = this.#options;
|
|
3822
|
+
if (!e.key || e.key.length !== 1 || e.altKey || e.ctrlKey || e.metaKey) {
|
|
3823
|
+
return;
|
|
3824
|
+
}
|
|
3825
|
+
if (separateDialCode && allowDropdown && countrySearch && e.key === "+") {
|
|
3826
|
+
e.preventDefault();
|
|
3827
|
+
this.#openDropdownWithPlus();
|
|
3828
|
+
return;
|
|
3829
|
+
}
|
|
3830
|
+
if (!strictMode) {
|
|
3831
|
+
return;
|
|
3832
|
+
}
|
|
3833
|
+
const inputValue = this.#getTelInputValue();
|
|
3834
|
+
const alreadyHasPlus = inputValue.startsWith("+");
|
|
3835
|
+
const isInitialPlus = !alreadyHasPlus && this.#ui.telInputEl.selectionStart === 0 && e.key === "+";
|
|
3836
|
+
const normalisedKey = this.#numerals.normalise(e.key);
|
|
3837
|
+
const isNumeric = /^[0-9]$/.test(normalisedKey);
|
|
3838
|
+
const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
|
|
3839
|
+
const input = this.#ui.telInputEl;
|
|
3840
|
+
const selStart = input.selectionStart;
|
|
3841
|
+
const selEnd = input.selectionEnd;
|
|
3842
|
+
const before = inputValue.slice(0, selStart ?? void 0);
|
|
3843
|
+
const after = inputValue.slice(selEnd ?? void 0);
|
|
3844
|
+
const newValue = before + normalisedKey + after;
|
|
3845
|
+
const newFullNumber = this.#buildFullNumber(newValue);
|
|
3846
|
+
let hasExceededMaxLength = false;
|
|
3847
|
+
if (intlTelInput.utils && this.#maxCoreNumberLength) {
|
|
3848
|
+
const coreNumber = intlTelInput.utils.getCoreNumber(
|
|
3849
|
+
newFullNumber,
|
|
3850
|
+
this.#selectedCountry?.iso2
|
|
3851
|
+
);
|
|
3852
|
+
hasExceededMaxLength = coreNumber.length > this.#maxCoreNumberLength;
|
|
3853
|
+
}
|
|
3854
|
+
const newCountry = this.#resolveCountryChangeFromNumber(newFullNumber);
|
|
3855
|
+
const isChangingDialCode = newCountry !== null;
|
|
3856
|
+
if (!isAllowedChar || hasExceededMaxLength && !isChangingDialCode && !isInitialPlus) {
|
|
3857
|
+
this.#dispatchEvent(EVENTS.STRICT_REJECT, {
|
|
3858
|
+
source: "key",
|
|
3859
|
+
rejectedInput: e.key,
|
|
3860
|
+
reason: !isAllowedChar ? "invalid" : "max-length"
|
|
3861
|
+
});
|
|
3862
|
+
e.preventDefault();
|
|
3863
|
+
}
|
|
3864
|
+
};
|
|
3845
3865
|
#bindPasteListener() {
|
|
3846
3866
|
if (!this.#options.strictMode) {
|
|
3847
3867
|
return;
|
|
3848
3868
|
}
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3869
|
+
this.#ui.telInputEl.addEventListener("paste", this.#handlePasteEvent, {
|
|
3870
|
+
signal: this.#abortController.signal
|
|
3871
|
+
});
|
|
3872
|
+
}
|
|
3873
|
+
#handlePasteEvent = (e) => {
|
|
3874
|
+
e.preventDefault();
|
|
3875
|
+
const input = this.#ui.telInputEl;
|
|
3876
|
+
const selStart = input.selectionStart;
|
|
3877
|
+
const selEnd = input.selectionEnd;
|
|
3878
|
+
const inputValue = this.#getTelInputValue();
|
|
3879
|
+
const before = inputValue.slice(0, selStart ?? void 0);
|
|
3880
|
+
const after = inputValue.slice(selEnd ?? void 0);
|
|
3881
|
+
const iso2 = this.#selectedCountry?.iso2;
|
|
3882
|
+
const pastedRaw = e.clipboardData.getData("text");
|
|
3883
|
+
const pasted = this.#numerals.normalise(pastedRaw);
|
|
3884
|
+
const initialCharSelected = selStart === 0 && selEnd > 0;
|
|
3885
|
+
const allowLeadingPlus = !inputValue.startsWith("+") || initialCharSelected;
|
|
3886
|
+
const allowedChars = pasted.replace(REGEX.NON_PLUS_NUMERIC_GLOBAL, "");
|
|
3887
|
+
const hasLeadingPlus = allowedChars.startsWith("+");
|
|
3888
|
+
const numerics = allowedChars.replace(/\+/g, "");
|
|
3889
|
+
const sanitised = hasLeadingPlus && allowLeadingPlus ? `+${numerics}` : numerics;
|
|
3890
|
+
let newValue = before + sanitised + after;
|
|
3891
|
+
let rejectReason = sanitised !== pasted ? "invalid" : null;
|
|
3892
|
+
if (newValue.length > 5 && intlTelInput.utils) {
|
|
3893
|
+
let coreNumber = intlTelInput.utils.getCoreNumber(newValue, iso2);
|
|
3894
|
+
while (coreNumber.length === 0 && newValue.length > 0) {
|
|
3895
|
+
newValue = newValue.slice(0, -1);
|
|
3896
|
+
coreNumber = intlTelInput.utils.getCoreNumber(newValue, iso2);
|
|
3897
|
+
}
|
|
3898
|
+
if (!coreNumber) {
|
|
3899
|
+
this.#dispatchEvent(EVENTS.STRICT_REJECT, {
|
|
3900
|
+
source: "paste",
|
|
3901
|
+
rejectedInput: pastedRaw,
|
|
3902
|
+
reason: "max-length"
|
|
3903
|
+
});
|
|
3904
|
+
return;
|
|
3905
|
+
}
|
|
3906
|
+
if (this.#maxCoreNumberLength && coreNumber.length > this.#maxCoreNumberLength) {
|
|
3907
|
+
if (input.selectionEnd === inputValue.length) {
|
|
3908
|
+
const trimLength = coreNumber.length - this.#maxCoreNumberLength;
|
|
3909
|
+
newValue = newValue.slice(0, newValue.length - trimLength);
|
|
3910
|
+
rejectReason = "max-length";
|
|
3911
|
+
} else {
|
|
3875
3912
|
this.#dispatchEvent(EVENTS.STRICT_REJECT, {
|
|
3876
3913
|
source: "paste",
|
|
3877
3914
|
rejectedInput: pastedRaw,
|
|
@@ -3879,37 +3916,20 @@ var Iti = class _Iti {
|
|
|
3879
3916
|
});
|
|
3880
3917
|
return;
|
|
3881
3918
|
}
|
|
3882
|
-
if (this.#maxCoreNumberLength && coreNumber.length > this.#maxCoreNumberLength) {
|
|
3883
|
-
if (input.selectionEnd === inputValue.length) {
|
|
3884
|
-
const trimLength = coreNumber.length - this.#maxCoreNumberLength;
|
|
3885
|
-
newValue = newValue.slice(0, newValue.length - trimLength);
|
|
3886
|
-
rejectReason = "max-length";
|
|
3887
|
-
} else {
|
|
3888
|
-
this.#dispatchEvent(EVENTS.STRICT_REJECT, {
|
|
3889
|
-
source: "paste",
|
|
3890
|
-
rejectedInput: pastedRaw,
|
|
3891
|
-
reason: "max-length"
|
|
3892
|
-
});
|
|
3893
|
-
return;
|
|
3894
|
-
}
|
|
3895
|
-
}
|
|
3896
3919
|
}
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
}
|
|
3908
|
-
}
|
|
3909
|
-
|
|
3910
|
-
signal: this.#abortController.signal
|
|
3911
|
-
});
|
|
3912
|
-
}
|
|
3920
|
+
}
|
|
3921
|
+
this.#setTelInputValue(newValue);
|
|
3922
|
+
const caretPos = selStart + sanitised.length;
|
|
3923
|
+
input.setSelectionRange(caretPos, caretPos);
|
|
3924
|
+
input.dispatchEvent(new InputEvent("input", { bubbles: true }));
|
|
3925
|
+
if (rejectReason) {
|
|
3926
|
+
this.#dispatchEvent(EVENTS.STRICT_REJECT, {
|
|
3927
|
+
source: "paste",
|
|
3928
|
+
rejectedInput: pastedRaw,
|
|
3929
|
+
reason: rejectReason
|
|
3930
|
+
});
|
|
3931
|
+
}
|
|
3932
|
+
};
|
|
3913
3933
|
//* Adhere to the input's maxlength attr.
|
|
3914
3934
|
#truncateToMaxLength(number) {
|
|
3915
3935
|
const max = Number(this.#ui.telInputEl.getAttribute("maxlength"));
|
|
@@ -4551,7 +4571,7 @@ var intlTelInput = Object.assign(
|
|
|
4551
4571
|
attachUtils,
|
|
4552
4572
|
startedLoadingUtils: false,
|
|
4553
4573
|
startedLoadingAutoCountry: false,
|
|
4554
|
-
version: "27.
|
|
4574
|
+
version: "27.2.0"
|
|
4555
4575
|
}
|
|
4556
4576
|
);
|
|
4557
4577
|
var intlTelInput_default = intlTelInput;
|
package/package.json
CHANGED
package/react/README.md
CHANGED
|
@@ -3,3 +3,11 @@
|
|
|
3
3
|
A React component for the [intl-tel-input](https://github.com/jackocnr/intl-tel-input) JavaScript plugin. View the [source code](https://github.com/jackocnr/intl-tel-input/blob/master/react/src/IntlTelInput.tsx).
|
|
4
4
|
|
|
5
5
|
[Explore docs »](https://intl-tel-input.com/docs/react-component)
|
|
6
|
+
|
|
7
|
+
## Running the demos locally
|
|
8
|
+
|
|
9
|
+
1. Initialise the submodules: `git submodule update --init --recursive`
|
|
10
|
+
2. Install dependencies: `npm install`
|
|
11
|
+
3. Build: `npm run build`
|
|
12
|
+
|
|
13
|
+
You can then open `react/demo/validation/index.html` in your browser to try the validation demo. View the full list of [available demos](https://github.com/jackocnr/intl-tel-input/tree/master/react/demo).
|
|
@@ -2,6 +2,8 @@ import intlTelInput, { Iti } from "intl-tel-input";
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
export { intlTelInput };
|
|
4
4
|
type InputProps = Omit<React.ComponentPropsWithoutRef<"input">, "onInput">;
|
|
5
|
+
export type StrictRejectSource = "key" | "paste";
|
|
6
|
+
export type StrictRejectReason = "invalid" | "max-length";
|
|
5
7
|
export type IntlTelInputRef = {
|
|
6
8
|
getInstance: () => Iti | null;
|
|
7
9
|
getInput: () => HTMLInputElement | null;
|
|
@@ -11,6 +13,9 @@ declare const IntlTelInput: React.ForwardRefExoticComponent<Partial<import("intl
|
|
|
11
13
|
onChangeCountry?: (iso2: string) => void;
|
|
12
14
|
onChangeValidity?: (isValid: boolean) => void;
|
|
13
15
|
onChangeErrorCode?: (errorCode: number | null) => void;
|
|
16
|
+
onOpenCountryDropdown?: () => void;
|
|
17
|
+
onCloseCountryDropdown?: () => void;
|
|
18
|
+
onStrictReject?: (source: StrictRejectSource, rejectedInput: string, reason: StrictRejectReason) => void;
|
|
14
19
|
usePreciseValidation?: boolean;
|
|
15
20
|
inputProps?: InputProps;
|
|
16
21
|
disabled?: boolean | undefined;
|