intl-tel-input 24.2.0 → 24.3.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/README.md +31 -28
- package/build/css/intlTelInput.css +1 -30
- package/build/css/intlTelInput.min.css +1 -1
- package/build/js/data.js +1 -1
- package/build/js/data.min.js +1 -1
- package/build/js/intlTelInput.d.ts +3 -0
- package/build/js/intlTelInput.js +36 -24
- package/build/js/intlTelInput.min.js +2 -2
- package/build/js/intlTelInputWithUtils.js +36 -24
- package/build/js/intlTelInputWithUtils.min.js +2 -2
- package/package.json +1 -1
- package/react/README.md +1 -1
- package/react/build/IntlTelInput.cjs +35 -23
- package/react/build/IntlTelInput.d.ts +3 -0
- package/react/build/IntlTelInput.js +35 -23
- package/react/build/IntlTelInputWithUtils.cjs +35 -23
- package/react/build/IntlTelInputWithUtils.js +35 -23
package/package.json
CHANGED
package/react/README.md
CHANGED
|
@@ -29,7 +29,7 @@ import "intl-tel-input/styles";
|
|
|
29
29
|
|
|
30
30
|
See the [Validation demo](https://github.com/jackocnr/intl-tel-input/blob/master/react/demo/ValidationApp.tsx) for a more fleshed-out example of how to handle validation.
|
|
31
31
|
|
|
32
|
-
A note on the utils script (~260KB): if you're lazy loading the IntlTelInput chunk (and so less worried about filesize) then you can just import IntlTelInput from `"intl-tel-input/reactWithUtils"` instead, to include the utils script. Alternatively, if you use the main `"intl-tel-input/react"` import, then you should couple this with the `utilsScript` initialisation option - you will need to host the [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file, and then set the `utilsScript` option to that URL, or alternatively just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@24.
|
|
32
|
+
A note on the utils script (~260KB): if you're lazy loading the IntlTelInput chunk (and so less worried about filesize) then you can just import IntlTelInput from `"intl-tel-input/reactWithUtils"` instead, to include the utils script. Alternatively, if you use the main `"intl-tel-input/react"` import, then you should couple this with the `utilsScript` initialisation option - you will need to host the [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file, and then set the `utilsScript` option to that URL, or alternatively just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@24.3.0/build/js/utils.js"`.
|
|
33
33
|
|
|
34
34
|
## Props
|
|
35
35
|
Here's a list of all of the current props you can pass to the IntlTelInput react component.
|
|
@@ -1758,12 +1758,14 @@ var Iti = class {
|
|
|
1758
1758
|
if (this.options.useFullscreenPopup) {
|
|
1759
1759
|
this.options.fixDropdownWidth = false;
|
|
1760
1760
|
}
|
|
1761
|
+
if (this.options.onlyCountries.length === 1) {
|
|
1762
|
+
this.options.initialCountry = this.options.onlyCountries[0];
|
|
1763
|
+
}
|
|
1761
1764
|
if (this.options.separateDialCode) {
|
|
1762
|
-
this.options.allowDropdown = true;
|
|
1763
1765
|
this.options.nationalMode = false;
|
|
1764
1766
|
this.options.countrySearch = true;
|
|
1765
1767
|
}
|
|
1766
|
-
if (!this.options.showFlags && !this.options.separateDialCode) {
|
|
1768
|
+
if (this.options.allowDropdown && !this.options.showFlags && !this.options.separateDialCode) {
|
|
1767
1769
|
this.options.nationalMode = false;
|
|
1768
1770
|
}
|
|
1769
1771
|
if (this.options.useFullscreenPopup && !this.options.dropdownContainer) {
|
|
@@ -1771,6 +1773,8 @@ var Iti = class {
|
|
|
1771
1773
|
}
|
|
1772
1774
|
this.isAndroid = typeof navigator !== "undefined" ? /Android/i.test(navigator.userAgent) : false;
|
|
1773
1775
|
this.isRTL = !!this.telInput.closest("[dir=rtl]");
|
|
1776
|
+
const showOnDefaultSide = this.options.allowDropdown || this.options.separateDialCode;
|
|
1777
|
+
this.showSelectedCountryOnLeft = this.isRTL ? !showOnDefaultSide : showOnDefaultSide;
|
|
1774
1778
|
if (this.options.separateDialCode) {
|
|
1775
1779
|
if (this.isRTL) {
|
|
1776
1780
|
this.originalPaddingRight = this.telInput.style.paddingRight;
|
|
@@ -1934,10 +1938,13 @@ var Iti = class {
|
|
|
1934
1938
|
}
|
|
1935
1939
|
const wrapper = createEl("div", { class: parentClass });
|
|
1936
1940
|
this.telInput.parentNode?.insertBefore(wrapper, this.telInput);
|
|
1937
|
-
if (allowDropdown || showFlags) {
|
|
1941
|
+
if (allowDropdown || showFlags || separateDialCode) {
|
|
1938
1942
|
this.countryContainer = createEl(
|
|
1939
1943
|
"div",
|
|
1940
|
-
{
|
|
1944
|
+
{
|
|
1945
|
+
class: "iti__country-container",
|
|
1946
|
+
style: this.showSelectedCountryOnLeft ? "left: 0" : "right: 0"
|
|
1947
|
+
},
|
|
1941
1948
|
wrapper
|
|
1942
1949
|
);
|
|
1943
1950
|
if (allowDropdown) {
|
|
@@ -2042,6 +2049,7 @@ var Iti = class {
|
|
|
2042
2049
|
}
|
|
2043
2050
|
}
|
|
2044
2051
|
wrapper.appendChild(this.telInput);
|
|
2052
|
+
this._updateInputPadding();
|
|
2045
2053
|
if (hiddenInput) {
|
|
2046
2054
|
const telInputName = this.telInput.getAttribute("name") || "";
|
|
2047
2055
|
const names = hiddenInput(telInputName);
|
|
@@ -2228,25 +2236,25 @@ var Iti = class {
|
|
|
2228
2236
|
}
|
|
2229
2237
|
}
|
|
2230
2238
|
}
|
|
2239
|
+
_openDropdownWithPlus() {
|
|
2240
|
+
this._openDropdown();
|
|
2241
|
+
this.searchInput.value = "+";
|
|
2242
|
+
this._filterCountries("", true);
|
|
2243
|
+
}
|
|
2231
2244
|
//* Initialize the tel input listeners.
|
|
2232
2245
|
_initTelInputListeners() {
|
|
2233
|
-
const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay } = this.options;
|
|
2246
|
+
const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay, allowDropdown } = this.options;
|
|
2234
2247
|
let userOverrideFormatting = false;
|
|
2235
2248
|
if (/\p{L}/u.test(this.telInput.value)) {
|
|
2236
2249
|
userOverrideFormatting = true;
|
|
2237
2250
|
}
|
|
2238
|
-
const openDropdownWithPlus = () => {
|
|
2239
|
-
this._openDropdown();
|
|
2240
|
-
this.searchInput.value = "+";
|
|
2241
|
-
this._filterCountries("", true);
|
|
2242
|
-
};
|
|
2243
2251
|
this._handleInputEvent = (e) => {
|
|
2244
|
-
if (this.isAndroid && e?.data === "+" && separateDialCode) {
|
|
2252
|
+
if (this.isAndroid && e?.data === "+" && separateDialCode && allowDropdown) {
|
|
2245
2253
|
const currentCaretPos = this.telInput.selectionStart || 0;
|
|
2246
2254
|
const valueBeforeCaret = this.telInput.value.substring(0, currentCaretPos - 1);
|
|
2247
2255
|
const valueAfterCaret = this.telInput.value.substring(currentCaretPos);
|
|
2248
2256
|
this.telInput.value = valueBeforeCaret + valueAfterCaret;
|
|
2249
|
-
|
|
2257
|
+
this._openDropdownWithPlus();
|
|
2250
2258
|
return;
|
|
2251
2259
|
}
|
|
2252
2260
|
if (this._updateCountryFromNumber(this.telInput.value)) {
|
|
@@ -2275,15 +2283,15 @@ var Iti = class {
|
|
|
2275
2283
|
if (strictMode || separateDialCode) {
|
|
2276
2284
|
this._handleKeydownEvent = (e) => {
|
|
2277
2285
|
if (e.key && e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {
|
|
2278
|
-
if (separateDialCode && e.key === "+") {
|
|
2286
|
+
if (separateDialCode && allowDropdown && e.key === "+") {
|
|
2279
2287
|
e.preventDefault();
|
|
2280
|
-
|
|
2288
|
+
this._openDropdownWithPlus();
|
|
2281
2289
|
return;
|
|
2282
2290
|
}
|
|
2283
2291
|
if (strictMode) {
|
|
2284
2292
|
const isInitialPlus = this.telInput.selectionStart === 0 && e.key === "+";
|
|
2285
2293
|
const isNumeric = /^[0-9]$/.test(e.key);
|
|
2286
|
-
const isAllowedChar = isInitialPlus || isNumeric;
|
|
2294
|
+
const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
|
|
2287
2295
|
const fullNumber = this._getFullNumber();
|
|
2288
2296
|
const coreNumber = intlTelInput.utils.getCoreNumber(fullNumber, this.selectedCountryData.iso2);
|
|
2289
2297
|
const hasReachedMaxLength = this.maxCoreNumberLength && coreNumber.length >= this.maxCoreNumberLength;
|
|
@@ -2618,18 +2626,22 @@ var Iti = class {
|
|
|
2618
2626
|
if (separateDialCode) {
|
|
2619
2627
|
const dialCode = this.selectedCountryData.dialCode ? `+${this.selectedCountryData.dialCode}` : "";
|
|
2620
2628
|
this.selectedDialCode.innerHTML = dialCode;
|
|
2621
|
-
|
|
2622
|
-
const inputPadding = selectedCountryWidth + 8;
|
|
2623
|
-
if (this.isRTL) {
|
|
2624
|
-
this.telInput.style.paddingRight = `${inputPadding}px`;
|
|
2625
|
-
} else {
|
|
2626
|
-
this.telInput.style.paddingLeft = `${inputPadding}px`;
|
|
2627
|
-
}
|
|
2629
|
+
this._updateInputPadding();
|
|
2628
2630
|
}
|
|
2629
2631
|
this._updatePlaceholder();
|
|
2630
2632
|
this._updateMaxLength();
|
|
2631
2633
|
return prevCountry.iso2 !== iso2;
|
|
2632
2634
|
}
|
|
2635
|
+
//* Update the input padding to make space for the selected country/dial code.
|
|
2636
|
+
_updateInputPadding() {
|
|
2637
|
+
const selectedCountryWidth = this.selectedCountry.offsetWidth || this._getHiddenSelectedCountryWidth();
|
|
2638
|
+
const inputPadding = selectedCountryWidth + 6;
|
|
2639
|
+
if (this.showSelectedCountryOnLeft) {
|
|
2640
|
+
this.telInput.style.paddingLeft = `${inputPadding}px`;
|
|
2641
|
+
} else {
|
|
2642
|
+
this.telInput.style.paddingRight = `${inputPadding}px`;
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2633
2645
|
//* Update the maximum valid number length for the currently selected country.
|
|
2634
2646
|
_updateMaxLength() {
|
|
2635
2647
|
const { strictMode, placeholderNumberType, validationNumberType } = this.options;
|
|
@@ -3079,7 +3091,7 @@ var intlTelInput = Object.assign(
|
|
|
3079
3091
|
//* A map from instance ID to instance object.
|
|
3080
3092
|
instances: {},
|
|
3081
3093
|
loadUtils,
|
|
3082
|
-
version: "24.
|
|
3094
|
+
version: "24.3.0"
|
|
3083
3095
|
}
|
|
3084
3096
|
);
|
|
3085
3097
|
var intl_tel_input_default = intlTelInput;
|
|
@@ -364,6 +364,7 @@ declare module "intl-tel-input" {
|
|
|
364
364
|
private options;
|
|
365
365
|
private hadInitialPlaceholder;
|
|
366
366
|
private isRTL;
|
|
367
|
+
private showSelectedCountryOnLeft;
|
|
367
368
|
private isAndroid;
|
|
368
369
|
private selectedCountryData;
|
|
369
370
|
private countries;
|
|
@@ -419,6 +420,7 @@ declare module "intl-tel-input" {
|
|
|
419
420
|
private _initDropdownListeners;
|
|
420
421
|
private _initRequests;
|
|
421
422
|
private _loadAutoCountry;
|
|
423
|
+
private _openDropdownWithPlus;
|
|
422
424
|
private _initTelInputListeners;
|
|
423
425
|
private _cap;
|
|
424
426
|
private _trigger;
|
|
@@ -435,6 +437,7 @@ declare module "intl-tel-input" {
|
|
|
435
437
|
private _highlightListItem;
|
|
436
438
|
private _getCountryData;
|
|
437
439
|
private _setCountry;
|
|
440
|
+
private _updateInputPadding;
|
|
438
441
|
private _updateMaxLength;
|
|
439
442
|
private _setSelectedCountryTitleAttribute;
|
|
440
443
|
private _getHiddenSelectedCountryWidth;
|
|
@@ -1722,12 +1722,14 @@ var Iti = class {
|
|
|
1722
1722
|
if (this.options.useFullscreenPopup) {
|
|
1723
1723
|
this.options.fixDropdownWidth = false;
|
|
1724
1724
|
}
|
|
1725
|
+
if (this.options.onlyCountries.length === 1) {
|
|
1726
|
+
this.options.initialCountry = this.options.onlyCountries[0];
|
|
1727
|
+
}
|
|
1725
1728
|
if (this.options.separateDialCode) {
|
|
1726
|
-
this.options.allowDropdown = true;
|
|
1727
1729
|
this.options.nationalMode = false;
|
|
1728
1730
|
this.options.countrySearch = true;
|
|
1729
1731
|
}
|
|
1730
|
-
if (!this.options.showFlags && !this.options.separateDialCode) {
|
|
1732
|
+
if (this.options.allowDropdown && !this.options.showFlags && !this.options.separateDialCode) {
|
|
1731
1733
|
this.options.nationalMode = false;
|
|
1732
1734
|
}
|
|
1733
1735
|
if (this.options.useFullscreenPopup && !this.options.dropdownContainer) {
|
|
@@ -1735,6 +1737,8 @@ var Iti = class {
|
|
|
1735
1737
|
}
|
|
1736
1738
|
this.isAndroid = typeof navigator !== "undefined" ? /Android/i.test(navigator.userAgent) : false;
|
|
1737
1739
|
this.isRTL = !!this.telInput.closest("[dir=rtl]");
|
|
1740
|
+
const showOnDefaultSide = this.options.allowDropdown || this.options.separateDialCode;
|
|
1741
|
+
this.showSelectedCountryOnLeft = this.isRTL ? !showOnDefaultSide : showOnDefaultSide;
|
|
1738
1742
|
if (this.options.separateDialCode) {
|
|
1739
1743
|
if (this.isRTL) {
|
|
1740
1744
|
this.originalPaddingRight = this.telInput.style.paddingRight;
|
|
@@ -1898,10 +1902,13 @@ var Iti = class {
|
|
|
1898
1902
|
}
|
|
1899
1903
|
const wrapper = createEl("div", { class: parentClass });
|
|
1900
1904
|
this.telInput.parentNode?.insertBefore(wrapper, this.telInput);
|
|
1901
|
-
if (allowDropdown || showFlags) {
|
|
1905
|
+
if (allowDropdown || showFlags || separateDialCode) {
|
|
1902
1906
|
this.countryContainer = createEl(
|
|
1903
1907
|
"div",
|
|
1904
|
-
{
|
|
1908
|
+
{
|
|
1909
|
+
class: "iti__country-container",
|
|
1910
|
+
style: this.showSelectedCountryOnLeft ? "left: 0" : "right: 0"
|
|
1911
|
+
},
|
|
1905
1912
|
wrapper
|
|
1906
1913
|
);
|
|
1907
1914
|
if (allowDropdown) {
|
|
@@ -2006,6 +2013,7 @@ var Iti = class {
|
|
|
2006
2013
|
}
|
|
2007
2014
|
}
|
|
2008
2015
|
wrapper.appendChild(this.telInput);
|
|
2016
|
+
this._updateInputPadding();
|
|
2009
2017
|
if (hiddenInput) {
|
|
2010
2018
|
const telInputName = this.telInput.getAttribute("name") || "";
|
|
2011
2019
|
const names = hiddenInput(telInputName);
|
|
@@ -2192,25 +2200,25 @@ var Iti = class {
|
|
|
2192
2200
|
}
|
|
2193
2201
|
}
|
|
2194
2202
|
}
|
|
2203
|
+
_openDropdownWithPlus() {
|
|
2204
|
+
this._openDropdown();
|
|
2205
|
+
this.searchInput.value = "+";
|
|
2206
|
+
this._filterCountries("", true);
|
|
2207
|
+
}
|
|
2195
2208
|
//* Initialize the tel input listeners.
|
|
2196
2209
|
_initTelInputListeners() {
|
|
2197
|
-
const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay } = this.options;
|
|
2210
|
+
const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay, allowDropdown } = this.options;
|
|
2198
2211
|
let userOverrideFormatting = false;
|
|
2199
2212
|
if (/\p{L}/u.test(this.telInput.value)) {
|
|
2200
2213
|
userOverrideFormatting = true;
|
|
2201
2214
|
}
|
|
2202
|
-
const openDropdownWithPlus = () => {
|
|
2203
|
-
this._openDropdown();
|
|
2204
|
-
this.searchInput.value = "+";
|
|
2205
|
-
this._filterCountries("", true);
|
|
2206
|
-
};
|
|
2207
2215
|
this._handleInputEvent = (e) => {
|
|
2208
|
-
if (this.isAndroid && e?.data === "+" && separateDialCode) {
|
|
2216
|
+
if (this.isAndroid && e?.data === "+" && separateDialCode && allowDropdown) {
|
|
2209
2217
|
const currentCaretPos = this.telInput.selectionStart || 0;
|
|
2210
2218
|
const valueBeforeCaret = this.telInput.value.substring(0, currentCaretPos - 1);
|
|
2211
2219
|
const valueAfterCaret = this.telInput.value.substring(currentCaretPos);
|
|
2212
2220
|
this.telInput.value = valueBeforeCaret + valueAfterCaret;
|
|
2213
|
-
|
|
2221
|
+
this._openDropdownWithPlus();
|
|
2214
2222
|
return;
|
|
2215
2223
|
}
|
|
2216
2224
|
if (this._updateCountryFromNumber(this.telInput.value)) {
|
|
@@ -2239,15 +2247,15 @@ var Iti = class {
|
|
|
2239
2247
|
if (strictMode || separateDialCode) {
|
|
2240
2248
|
this._handleKeydownEvent = (e) => {
|
|
2241
2249
|
if (e.key && e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {
|
|
2242
|
-
if (separateDialCode && e.key === "+") {
|
|
2250
|
+
if (separateDialCode && allowDropdown && e.key === "+") {
|
|
2243
2251
|
e.preventDefault();
|
|
2244
|
-
|
|
2252
|
+
this._openDropdownWithPlus();
|
|
2245
2253
|
return;
|
|
2246
2254
|
}
|
|
2247
2255
|
if (strictMode) {
|
|
2248
2256
|
const isInitialPlus = this.telInput.selectionStart === 0 && e.key === "+";
|
|
2249
2257
|
const isNumeric = /^[0-9]$/.test(e.key);
|
|
2250
|
-
const isAllowedChar = isInitialPlus || isNumeric;
|
|
2258
|
+
const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
|
|
2251
2259
|
const fullNumber = this._getFullNumber();
|
|
2252
2260
|
const coreNumber = intlTelInput.utils.getCoreNumber(fullNumber, this.selectedCountryData.iso2);
|
|
2253
2261
|
const hasReachedMaxLength = this.maxCoreNumberLength && coreNumber.length >= this.maxCoreNumberLength;
|
|
@@ -2582,18 +2590,22 @@ var Iti = class {
|
|
|
2582
2590
|
if (separateDialCode) {
|
|
2583
2591
|
const dialCode = this.selectedCountryData.dialCode ? `+${this.selectedCountryData.dialCode}` : "";
|
|
2584
2592
|
this.selectedDialCode.innerHTML = dialCode;
|
|
2585
|
-
|
|
2586
|
-
const inputPadding = selectedCountryWidth + 8;
|
|
2587
|
-
if (this.isRTL) {
|
|
2588
|
-
this.telInput.style.paddingRight = `${inputPadding}px`;
|
|
2589
|
-
} else {
|
|
2590
|
-
this.telInput.style.paddingLeft = `${inputPadding}px`;
|
|
2591
|
-
}
|
|
2593
|
+
this._updateInputPadding();
|
|
2592
2594
|
}
|
|
2593
2595
|
this._updatePlaceholder();
|
|
2594
2596
|
this._updateMaxLength();
|
|
2595
2597
|
return prevCountry.iso2 !== iso2;
|
|
2596
2598
|
}
|
|
2599
|
+
//* Update the input padding to make space for the selected country/dial code.
|
|
2600
|
+
_updateInputPadding() {
|
|
2601
|
+
const selectedCountryWidth = this.selectedCountry.offsetWidth || this._getHiddenSelectedCountryWidth();
|
|
2602
|
+
const inputPadding = selectedCountryWidth + 6;
|
|
2603
|
+
if (this.showSelectedCountryOnLeft) {
|
|
2604
|
+
this.telInput.style.paddingLeft = `${inputPadding}px`;
|
|
2605
|
+
} else {
|
|
2606
|
+
this.telInput.style.paddingRight = `${inputPadding}px`;
|
|
2607
|
+
}
|
|
2608
|
+
}
|
|
2597
2609
|
//* Update the maximum valid number length for the currently selected country.
|
|
2598
2610
|
_updateMaxLength() {
|
|
2599
2611
|
const { strictMode, placeholderNumberType, validationNumberType } = this.options;
|
|
@@ -3043,7 +3055,7 @@ var intlTelInput = Object.assign(
|
|
|
3043
3055
|
//* A map from instance ID to instance object.
|
|
3044
3056
|
instances: {},
|
|
3045
3057
|
loadUtils,
|
|
3046
|
-
version: "24.
|
|
3058
|
+
version: "24.3.0"
|
|
3047
3059
|
}
|
|
3048
3060
|
);
|
|
3049
3061
|
var intl_tel_input_default = intlTelInput;
|
|
@@ -1758,12 +1758,14 @@ var Iti = class {
|
|
|
1758
1758
|
if (this.options.useFullscreenPopup) {
|
|
1759
1759
|
this.options.fixDropdownWidth = false;
|
|
1760
1760
|
}
|
|
1761
|
+
if (this.options.onlyCountries.length === 1) {
|
|
1762
|
+
this.options.initialCountry = this.options.onlyCountries[0];
|
|
1763
|
+
}
|
|
1761
1764
|
if (this.options.separateDialCode) {
|
|
1762
|
-
this.options.allowDropdown = true;
|
|
1763
1765
|
this.options.nationalMode = false;
|
|
1764
1766
|
this.options.countrySearch = true;
|
|
1765
1767
|
}
|
|
1766
|
-
if (!this.options.showFlags && !this.options.separateDialCode) {
|
|
1768
|
+
if (this.options.allowDropdown && !this.options.showFlags && !this.options.separateDialCode) {
|
|
1767
1769
|
this.options.nationalMode = false;
|
|
1768
1770
|
}
|
|
1769
1771
|
if (this.options.useFullscreenPopup && !this.options.dropdownContainer) {
|
|
@@ -1771,6 +1773,8 @@ var Iti = class {
|
|
|
1771
1773
|
}
|
|
1772
1774
|
this.isAndroid = typeof navigator !== "undefined" ? /Android/i.test(navigator.userAgent) : false;
|
|
1773
1775
|
this.isRTL = !!this.telInput.closest("[dir=rtl]");
|
|
1776
|
+
const showOnDefaultSide = this.options.allowDropdown || this.options.separateDialCode;
|
|
1777
|
+
this.showSelectedCountryOnLeft = this.isRTL ? !showOnDefaultSide : showOnDefaultSide;
|
|
1774
1778
|
if (this.options.separateDialCode) {
|
|
1775
1779
|
if (this.isRTL) {
|
|
1776
1780
|
this.originalPaddingRight = this.telInput.style.paddingRight;
|
|
@@ -1934,10 +1938,13 @@ var Iti = class {
|
|
|
1934
1938
|
}
|
|
1935
1939
|
const wrapper = createEl("div", { class: parentClass });
|
|
1936
1940
|
this.telInput.parentNode?.insertBefore(wrapper, this.telInput);
|
|
1937
|
-
if (allowDropdown || showFlags) {
|
|
1941
|
+
if (allowDropdown || showFlags || separateDialCode) {
|
|
1938
1942
|
this.countryContainer = createEl(
|
|
1939
1943
|
"div",
|
|
1940
|
-
{
|
|
1944
|
+
{
|
|
1945
|
+
class: "iti__country-container",
|
|
1946
|
+
style: this.showSelectedCountryOnLeft ? "left: 0" : "right: 0"
|
|
1947
|
+
},
|
|
1941
1948
|
wrapper
|
|
1942
1949
|
);
|
|
1943
1950
|
if (allowDropdown) {
|
|
@@ -2042,6 +2049,7 @@ var Iti = class {
|
|
|
2042
2049
|
}
|
|
2043
2050
|
}
|
|
2044
2051
|
wrapper.appendChild(this.telInput);
|
|
2052
|
+
this._updateInputPadding();
|
|
2045
2053
|
if (hiddenInput) {
|
|
2046
2054
|
const telInputName = this.telInput.getAttribute("name") || "";
|
|
2047
2055
|
const names = hiddenInput(telInputName);
|
|
@@ -2228,25 +2236,25 @@ var Iti = class {
|
|
|
2228
2236
|
}
|
|
2229
2237
|
}
|
|
2230
2238
|
}
|
|
2239
|
+
_openDropdownWithPlus() {
|
|
2240
|
+
this._openDropdown();
|
|
2241
|
+
this.searchInput.value = "+";
|
|
2242
|
+
this._filterCountries("", true);
|
|
2243
|
+
}
|
|
2231
2244
|
//* Initialize the tel input listeners.
|
|
2232
2245
|
_initTelInputListeners() {
|
|
2233
|
-
const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay } = this.options;
|
|
2246
|
+
const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay, allowDropdown } = this.options;
|
|
2234
2247
|
let userOverrideFormatting = false;
|
|
2235
2248
|
if (/\p{L}/u.test(this.telInput.value)) {
|
|
2236
2249
|
userOverrideFormatting = true;
|
|
2237
2250
|
}
|
|
2238
|
-
const openDropdownWithPlus = () => {
|
|
2239
|
-
this._openDropdown();
|
|
2240
|
-
this.searchInput.value = "+";
|
|
2241
|
-
this._filterCountries("", true);
|
|
2242
|
-
};
|
|
2243
2251
|
this._handleInputEvent = (e) => {
|
|
2244
|
-
if (this.isAndroid && e?.data === "+" && separateDialCode) {
|
|
2252
|
+
if (this.isAndroid && e?.data === "+" && separateDialCode && allowDropdown) {
|
|
2245
2253
|
const currentCaretPos = this.telInput.selectionStart || 0;
|
|
2246
2254
|
const valueBeforeCaret = this.telInput.value.substring(0, currentCaretPos - 1);
|
|
2247
2255
|
const valueAfterCaret = this.telInput.value.substring(currentCaretPos);
|
|
2248
2256
|
this.telInput.value = valueBeforeCaret + valueAfterCaret;
|
|
2249
|
-
|
|
2257
|
+
this._openDropdownWithPlus();
|
|
2250
2258
|
return;
|
|
2251
2259
|
}
|
|
2252
2260
|
if (this._updateCountryFromNumber(this.telInput.value)) {
|
|
@@ -2275,15 +2283,15 @@ var Iti = class {
|
|
|
2275
2283
|
if (strictMode || separateDialCode) {
|
|
2276
2284
|
this._handleKeydownEvent = (e) => {
|
|
2277
2285
|
if (e.key && e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {
|
|
2278
|
-
if (separateDialCode && e.key === "+") {
|
|
2286
|
+
if (separateDialCode && allowDropdown && e.key === "+") {
|
|
2279
2287
|
e.preventDefault();
|
|
2280
|
-
|
|
2288
|
+
this._openDropdownWithPlus();
|
|
2281
2289
|
return;
|
|
2282
2290
|
}
|
|
2283
2291
|
if (strictMode) {
|
|
2284
2292
|
const isInitialPlus = this.telInput.selectionStart === 0 && e.key === "+";
|
|
2285
2293
|
const isNumeric = /^[0-9]$/.test(e.key);
|
|
2286
|
-
const isAllowedChar = isInitialPlus || isNumeric;
|
|
2294
|
+
const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
|
|
2287
2295
|
const fullNumber = this._getFullNumber();
|
|
2288
2296
|
const coreNumber = intlTelInput.utils.getCoreNumber(fullNumber, this.selectedCountryData.iso2);
|
|
2289
2297
|
const hasReachedMaxLength = this.maxCoreNumberLength && coreNumber.length >= this.maxCoreNumberLength;
|
|
@@ -2618,18 +2626,22 @@ var Iti = class {
|
|
|
2618
2626
|
if (separateDialCode) {
|
|
2619
2627
|
const dialCode = this.selectedCountryData.dialCode ? `+${this.selectedCountryData.dialCode}` : "";
|
|
2620
2628
|
this.selectedDialCode.innerHTML = dialCode;
|
|
2621
|
-
|
|
2622
|
-
const inputPadding = selectedCountryWidth + 8;
|
|
2623
|
-
if (this.isRTL) {
|
|
2624
|
-
this.telInput.style.paddingRight = `${inputPadding}px`;
|
|
2625
|
-
} else {
|
|
2626
|
-
this.telInput.style.paddingLeft = `${inputPadding}px`;
|
|
2627
|
-
}
|
|
2629
|
+
this._updateInputPadding();
|
|
2628
2630
|
}
|
|
2629
2631
|
this._updatePlaceholder();
|
|
2630
2632
|
this._updateMaxLength();
|
|
2631
2633
|
return prevCountry.iso2 !== iso2;
|
|
2632
2634
|
}
|
|
2635
|
+
//* Update the input padding to make space for the selected country/dial code.
|
|
2636
|
+
_updateInputPadding() {
|
|
2637
|
+
const selectedCountryWidth = this.selectedCountry.offsetWidth || this._getHiddenSelectedCountryWidth();
|
|
2638
|
+
const inputPadding = selectedCountryWidth + 6;
|
|
2639
|
+
if (this.showSelectedCountryOnLeft) {
|
|
2640
|
+
this.telInput.style.paddingLeft = `${inputPadding}px`;
|
|
2641
|
+
} else {
|
|
2642
|
+
this.telInput.style.paddingRight = `${inputPadding}px`;
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2633
2645
|
//* Update the maximum valid number length for the currently selected country.
|
|
2634
2646
|
_updateMaxLength() {
|
|
2635
2647
|
const { strictMode, placeholderNumberType, validationNumberType } = this.options;
|
|
@@ -3079,7 +3091,7 @@ var intlTelInput = Object.assign(
|
|
|
3079
3091
|
//* A map from instance ID to instance object.
|
|
3080
3092
|
instances: {},
|
|
3081
3093
|
loadUtils,
|
|
3082
|
-
version: "24.
|
|
3094
|
+
version: "24.3.0"
|
|
3083
3095
|
}
|
|
3084
3096
|
);
|
|
3085
3097
|
var intl_tel_input_default = intlTelInput;
|
|
@@ -1722,12 +1722,14 @@ var Iti = class {
|
|
|
1722
1722
|
if (this.options.useFullscreenPopup) {
|
|
1723
1723
|
this.options.fixDropdownWidth = false;
|
|
1724
1724
|
}
|
|
1725
|
+
if (this.options.onlyCountries.length === 1) {
|
|
1726
|
+
this.options.initialCountry = this.options.onlyCountries[0];
|
|
1727
|
+
}
|
|
1725
1728
|
if (this.options.separateDialCode) {
|
|
1726
|
-
this.options.allowDropdown = true;
|
|
1727
1729
|
this.options.nationalMode = false;
|
|
1728
1730
|
this.options.countrySearch = true;
|
|
1729
1731
|
}
|
|
1730
|
-
if (!this.options.showFlags && !this.options.separateDialCode) {
|
|
1732
|
+
if (this.options.allowDropdown && !this.options.showFlags && !this.options.separateDialCode) {
|
|
1731
1733
|
this.options.nationalMode = false;
|
|
1732
1734
|
}
|
|
1733
1735
|
if (this.options.useFullscreenPopup && !this.options.dropdownContainer) {
|
|
@@ -1735,6 +1737,8 @@ var Iti = class {
|
|
|
1735
1737
|
}
|
|
1736
1738
|
this.isAndroid = typeof navigator !== "undefined" ? /Android/i.test(navigator.userAgent) : false;
|
|
1737
1739
|
this.isRTL = !!this.telInput.closest("[dir=rtl]");
|
|
1740
|
+
const showOnDefaultSide = this.options.allowDropdown || this.options.separateDialCode;
|
|
1741
|
+
this.showSelectedCountryOnLeft = this.isRTL ? !showOnDefaultSide : showOnDefaultSide;
|
|
1738
1742
|
if (this.options.separateDialCode) {
|
|
1739
1743
|
if (this.isRTL) {
|
|
1740
1744
|
this.originalPaddingRight = this.telInput.style.paddingRight;
|
|
@@ -1898,10 +1902,13 @@ var Iti = class {
|
|
|
1898
1902
|
}
|
|
1899
1903
|
const wrapper = createEl("div", { class: parentClass });
|
|
1900
1904
|
this.telInput.parentNode?.insertBefore(wrapper, this.telInput);
|
|
1901
|
-
if (allowDropdown || showFlags) {
|
|
1905
|
+
if (allowDropdown || showFlags || separateDialCode) {
|
|
1902
1906
|
this.countryContainer = createEl(
|
|
1903
1907
|
"div",
|
|
1904
|
-
{
|
|
1908
|
+
{
|
|
1909
|
+
class: "iti__country-container",
|
|
1910
|
+
style: this.showSelectedCountryOnLeft ? "left: 0" : "right: 0"
|
|
1911
|
+
},
|
|
1905
1912
|
wrapper
|
|
1906
1913
|
);
|
|
1907
1914
|
if (allowDropdown) {
|
|
@@ -2006,6 +2013,7 @@ var Iti = class {
|
|
|
2006
2013
|
}
|
|
2007
2014
|
}
|
|
2008
2015
|
wrapper.appendChild(this.telInput);
|
|
2016
|
+
this._updateInputPadding();
|
|
2009
2017
|
if (hiddenInput) {
|
|
2010
2018
|
const telInputName = this.telInput.getAttribute("name") || "";
|
|
2011
2019
|
const names = hiddenInput(telInputName);
|
|
@@ -2192,25 +2200,25 @@ var Iti = class {
|
|
|
2192
2200
|
}
|
|
2193
2201
|
}
|
|
2194
2202
|
}
|
|
2203
|
+
_openDropdownWithPlus() {
|
|
2204
|
+
this._openDropdown();
|
|
2205
|
+
this.searchInput.value = "+";
|
|
2206
|
+
this._filterCountries("", true);
|
|
2207
|
+
}
|
|
2195
2208
|
//* Initialize the tel input listeners.
|
|
2196
2209
|
_initTelInputListeners() {
|
|
2197
|
-
const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay } = this.options;
|
|
2210
|
+
const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay, allowDropdown } = this.options;
|
|
2198
2211
|
let userOverrideFormatting = false;
|
|
2199
2212
|
if (/\p{L}/u.test(this.telInput.value)) {
|
|
2200
2213
|
userOverrideFormatting = true;
|
|
2201
2214
|
}
|
|
2202
|
-
const openDropdownWithPlus = () => {
|
|
2203
|
-
this._openDropdown();
|
|
2204
|
-
this.searchInput.value = "+";
|
|
2205
|
-
this._filterCountries("", true);
|
|
2206
|
-
};
|
|
2207
2215
|
this._handleInputEvent = (e) => {
|
|
2208
|
-
if (this.isAndroid && e?.data === "+" && separateDialCode) {
|
|
2216
|
+
if (this.isAndroid && e?.data === "+" && separateDialCode && allowDropdown) {
|
|
2209
2217
|
const currentCaretPos = this.telInput.selectionStart || 0;
|
|
2210
2218
|
const valueBeforeCaret = this.telInput.value.substring(0, currentCaretPos - 1);
|
|
2211
2219
|
const valueAfterCaret = this.telInput.value.substring(currentCaretPos);
|
|
2212
2220
|
this.telInput.value = valueBeforeCaret + valueAfterCaret;
|
|
2213
|
-
|
|
2221
|
+
this._openDropdownWithPlus();
|
|
2214
2222
|
return;
|
|
2215
2223
|
}
|
|
2216
2224
|
if (this._updateCountryFromNumber(this.telInput.value)) {
|
|
@@ -2239,15 +2247,15 @@ var Iti = class {
|
|
|
2239
2247
|
if (strictMode || separateDialCode) {
|
|
2240
2248
|
this._handleKeydownEvent = (e) => {
|
|
2241
2249
|
if (e.key && e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {
|
|
2242
|
-
if (separateDialCode && e.key === "+") {
|
|
2250
|
+
if (separateDialCode && allowDropdown && e.key === "+") {
|
|
2243
2251
|
e.preventDefault();
|
|
2244
|
-
|
|
2252
|
+
this._openDropdownWithPlus();
|
|
2245
2253
|
return;
|
|
2246
2254
|
}
|
|
2247
2255
|
if (strictMode) {
|
|
2248
2256
|
const isInitialPlus = this.telInput.selectionStart === 0 && e.key === "+";
|
|
2249
2257
|
const isNumeric = /^[0-9]$/.test(e.key);
|
|
2250
|
-
const isAllowedChar = isInitialPlus || isNumeric;
|
|
2258
|
+
const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
|
|
2251
2259
|
const fullNumber = this._getFullNumber();
|
|
2252
2260
|
const coreNumber = intlTelInput.utils.getCoreNumber(fullNumber, this.selectedCountryData.iso2);
|
|
2253
2261
|
const hasReachedMaxLength = this.maxCoreNumberLength && coreNumber.length >= this.maxCoreNumberLength;
|
|
@@ -2582,18 +2590,22 @@ var Iti = class {
|
|
|
2582
2590
|
if (separateDialCode) {
|
|
2583
2591
|
const dialCode = this.selectedCountryData.dialCode ? `+${this.selectedCountryData.dialCode}` : "";
|
|
2584
2592
|
this.selectedDialCode.innerHTML = dialCode;
|
|
2585
|
-
|
|
2586
|
-
const inputPadding = selectedCountryWidth + 8;
|
|
2587
|
-
if (this.isRTL) {
|
|
2588
|
-
this.telInput.style.paddingRight = `${inputPadding}px`;
|
|
2589
|
-
} else {
|
|
2590
|
-
this.telInput.style.paddingLeft = `${inputPadding}px`;
|
|
2591
|
-
}
|
|
2593
|
+
this._updateInputPadding();
|
|
2592
2594
|
}
|
|
2593
2595
|
this._updatePlaceholder();
|
|
2594
2596
|
this._updateMaxLength();
|
|
2595
2597
|
return prevCountry.iso2 !== iso2;
|
|
2596
2598
|
}
|
|
2599
|
+
//* Update the input padding to make space for the selected country/dial code.
|
|
2600
|
+
_updateInputPadding() {
|
|
2601
|
+
const selectedCountryWidth = this.selectedCountry.offsetWidth || this._getHiddenSelectedCountryWidth();
|
|
2602
|
+
const inputPadding = selectedCountryWidth + 6;
|
|
2603
|
+
if (this.showSelectedCountryOnLeft) {
|
|
2604
|
+
this.telInput.style.paddingLeft = `${inputPadding}px`;
|
|
2605
|
+
} else {
|
|
2606
|
+
this.telInput.style.paddingRight = `${inputPadding}px`;
|
|
2607
|
+
}
|
|
2608
|
+
}
|
|
2597
2609
|
//* Update the maximum valid number length for the currently selected country.
|
|
2598
2610
|
_updateMaxLength() {
|
|
2599
2611
|
const { strictMode, placeholderNumberType, validationNumberType } = this.options;
|
|
@@ -3043,7 +3055,7 @@ var intlTelInput = Object.assign(
|
|
|
3043
3055
|
//* A map from instance ID to instance object.
|
|
3044
3056
|
instances: {},
|
|
3045
3057
|
loadUtils,
|
|
3046
|
-
version: "24.
|
|
3058
|
+
version: "24.3.0"
|
|
3047
3059
|
}
|
|
3048
3060
|
);
|
|
3049
3061
|
var intl_tel_input_default = intlTelInput;
|