intl-tel-input 23.0.10 → 23.0.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intl-tel-input",
3
- "version": "23.0.10",
3
+ "version": "23.0.11",
4
4
  "description": "A JavaScript plugin for entering and validating international telephone numbers",
5
5
  "keywords": [
6
6
  "international",
package/react/README.md CHANGED
@@ -1,15 +1,16 @@
1
1
  # IntlTelInput React Component
2
- A React component wrapper for the [intl-tel-input](https://github.com/jackocnr/intl-tel-input) JavaScript plugin. View the source [here](https://github.com/jackocnr/intl-tel-input/blob/master/react/src/intl-tel-input/react.tsx).
2
+ A React component wrapper for the [intl-tel-input](https://github.com/jackocnr/intl-tel-input) JavaScript plugin. View the source code [here](https://github.com/jackocnr/intl-tel-input/blob/master/react/src/intl-tel-input/react.tsx).
3
3
 
4
4
  ## Table of Contents
5
5
  - [Demo and Examples](#demo-and-examples)
6
6
  - [Getting Started](#getting-started)
7
7
  - [Props](#props)
8
8
  - [Accessing Instance Methods](#accessing-instance-methods)
9
+ - [Accessing Static Methods](#accessing-static-methods)
9
10
  - [Troubleshooting](#troubleshooting)
10
11
 
11
12
  ## Demo and Examples
12
- Check out [Storybook](https://intl-tel-input.com/storybook) where you can play with the various options. Alternatively, try it for yourself by downloading the project and opening /react/demo/validation.html (etc) in a browser.
13
+ Check out [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--vanilla) where you can play with the various props. Alternatively, try it for yourself by downloading the project and opening /react/demo/validation.html (etc) in a browser.
13
14
 
14
15
  ## Getting Started
15
16
  ```js
@@ -28,7 +29,7 @@ import "intl-tel-input/styles";
28
29
 
29
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.
30
31
 
31
- A note on the utils script (~250kb): if you're lazy loading the IntlTelInput chunk (and so less worried about filesize) then you can just import `"intl-tel-input/reactWithUtils"` 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, and point that to your hosted [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file (or just point it to a CDN e.g. "https://cdn.jsdelivr.net/npm/intl-tel-input@23.0.9/build/js/utils.js").
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@23.0.11/build/js/utils.js"`.
32
33
 
33
34
  ## Props
34
35
  Here's a list of all of the current props you can pass to the IntlTelInput react component.
@@ -67,7 +68,11 @@ The props to pass to the input element e.g. `className`, `placeholder`, `require
67
68
 
68
69
  ## Accessing Instance Methods
69
70
 
70
- You can access the instance methods (`setNumber`, `setCountry`, `setPlaceholderNumberType` etc) by passing a ref into the IntlTelInput component (using the `ref` prop), and then calling `ref.current.getInstance()` e.g. `ref.current.getInstance().setNumber(...);`. See the [Set Number demo](https://github.com/jackocnr/intl-tel-input/blob/master/react/demo/SetNumberApp.tsx) for a full example. You can also access the input DOM element in a similar way: `ref.current.getInput()`.
71
+ You can access all of the plugin's [instance methods](https://github.com/jackocnr/intl-tel-input/blob/master/README.md#instance-methods) (`setNumber`, `setCountry`, `setPlaceholderNumberType` etc) by passing a ref into the IntlTelInput component (using the `ref` prop), and then calling `ref.current.getInstance()` e.g. `ref.current.getInstance().setNumber(...);`. See the [Set Number demo](https://github.com/jackocnr/intl-tel-input/blob/master/react/demo/SetNumberApp.tsx) for a full example. You can also access the input DOM element in a similar way: `ref.current.getInput()`.
72
+
73
+ ## Accessing Static Methods
74
+
75
+ You can access all of the plugin's [static methods](https://github.com/jackocnr/intl-tel-input/blob/master/README.md#static-methods) by importing `intlTelInput` from the same file as the react component e.g. `import { intlTelInput } from "intl-tel-input/react"` (note the lower case "i" in "intlTelInput"). You can then use this as you would with the main plugin e.g. `intlTelInput.getCountryData()` or `intlTelInput.utils.numberType` etc.
71
76
 
72
77
  ## Troubleshooting
73
78
 
@@ -1889,10 +1889,11 @@ var Iti = class {
1889
1889
  const val = useAttribute ? attributeValue : inputValue;
1890
1890
  const dialCode = this._getDialCode(val);
1891
1891
  const isRegionlessNanpNumber = isRegionlessNanp(val);
1892
- const { initialCountry } = this.options;
1892
+ const { initialCountry, geoIpLookup } = this.options;
1893
+ const isAutoCountry = initialCountry === "auto" && geoIpLookup;
1893
1894
  if (dialCode && !isRegionlessNanpNumber) {
1894
1895
  this._updateCountryFromNumber(val);
1895
- } else if (initialCountry !== "auto" || overrideAutoCountry) {
1896
+ } else if (!isAutoCountry || overrideAutoCountry) {
1896
1897
  const lowerInitialCountry = initialCountry ? initialCountry.toLowerCase() : "";
1897
1898
  const isValidInitialCountry = lowerInitialCountry && this._getCountryData(lowerInitialCountry, true);
1898
1899
  if (isValidInitialCountry) {
@@ -1971,18 +1972,20 @@ var Iti = class {
1971
1972
  }
1972
1973
  //* Init many requests: utils script / geo ip lookup.
1973
1974
  _initRequests() {
1974
- if (this.options.utilsScript && !intlTelInput.utils) {
1975
+ const { utilsScript, initialCountry, geoIpLookup } = this.options;
1976
+ if (utilsScript && !intlTelInput.utils) {
1975
1977
  if (intlTelInput.documentReady()) {
1976
- intlTelInput.loadUtils(this.options.utilsScript);
1978
+ intlTelInput.loadUtils(utilsScript);
1977
1979
  } else {
1978
1980
  window.addEventListener("load", () => {
1979
- intlTelInput.loadUtils(this.options.utilsScript);
1981
+ intlTelInput.loadUtils(utilsScript);
1980
1982
  });
1981
1983
  }
1982
1984
  } else {
1983
1985
  this.resolveUtilsScriptPromise();
1984
1986
  }
1985
- if (this.options.initialCountry === "auto" && !this.selectedCountryData.iso2) {
1987
+ const isAutoCountry = initialCountry === "auto" && geoIpLookup;
1988
+ if (isAutoCountry && !this.selectedCountryData.iso2) {
1986
1989
  this._loadAutoCountry();
1987
1990
  } else {
1988
1991
  this.resolveAutoCountryPromise();
@@ -2602,7 +2605,8 @@ var Iti = class {
2602
2605
  handleAutoCountry() {
2603
2606
  if (this.options.initialCountry === "auto" && intlTelInput.autoCountry) {
2604
2607
  this.defaultCountry = intlTelInput.autoCountry;
2605
- if (!this.telInput.value) {
2608
+ const hasSelectedCountryOrGlobe = this.selectedCountryData.iso2 || this.selectedCountryInner.classList.contains("iti__globe");
2609
+ if (!hasSelectedCountryOrGlobe) {
2606
2610
  this.setCountry(this.defaultCountry);
2607
2611
  }
2608
2612
  this.resolveAutoCountryPromise();
@@ -2780,7 +2784,7 @@ var intlTelInput = Object.assign(
2780
2784
  //* A map from instance ID to instance object.
2781
2785
  instances: {},
2782
2786
  loadUtils,
2783
- version: "23.0.10"
2787
+ version: "23.0.11"
2784
2788
  }
2785
2789
  );
2786
2790
  var intl_tel_input_default = intlTelInput;
@@ -1853,10 +1853,11 @@ var Iti = class {
1853
1853
  const val = useAttribute ? attributeValue : inputValue;
1854
1854
  const dialCode = this._getDialCode(val);
1855
1855
  const isRegionlessNanpNumber = isRegionlessNanp(val);
1856
- const { initialCountry } = this.options;
1856
+ const { initialCountry, geoIpLookup } = this.options;
1857
+ const isAutoCountry = initialCountry === "auto" && geoIpLookup;
1857
1858
  if (dialCode && !isRegionlessNanpNumber) {
1858
1859
  this._updateCountryFromNumber(val);
1859
- } else if (initialCountry !== "auto" || overrideAutoCountry) {
1860
+ } else if (!isAutoCountry || overrideAutoCountry) {
1860
1861
  const lowerInitialCountry = initialCountry ? initialCountry.toLowerCase() : "";
1861
1862
  const isValidInitialCountry = lowerInitialCountry && this._getCountryData(lowerInitialCountry, true);
1862
1863
  if (isValidInitialCountry) {
@@ -1935,18 +1936,20 @@ var Iti = class {
1935
1936
  }
1936
1937
  //* Init many requests: utils script / geo ip lookup.
1937
1938
  _initRequests() {
1938
- if (this.options.utilsScript && !intlTelInput.utils) {
1939
+ const { utilsScript, initialCountry, geoIpLookup } = this.options;
1940
+ if (utilsScript && !intlTelInput.utils) {
1939
1941
  if (intlTelInput.documentReady()) {
1940
- intlTelInput.loadUtils(this.options.utilsScript);
1942
+ intlTelInput.loadUtils(utilsScript);
1941
1943
  } else {
1942
1944
  window.addEventListener("load", () => {
1943
- intlTelInput.loadUtils(this.options.utilsScript);
1945
+ intlTelInput.loadUtils(utilsScript);
1944
1946
  });
1945
1947
  }
1946
1948
  } else {
1947
1949
  this.resolveUtilsScriptPromise();
1948
1950
  }
1949
- if (this.options.initialCountry === "auto" && !this.selectedCountryData.iso2) {
1951
+ const isAutoCountry = initialCountry === "auto" && geoIpLookup;
1952
+ if (isAutoCountry && !this.selectedCountryData.iso2) {
1950
1953
  this._loadAutoCountry();
1951
1954
  } else {
1952
1955
  this.resolveAutoCountryPromise();
@@ -2566,7 +2569,8 @@ var Iti = class {
2566
2569
  handleAutoCountry() {
2567
2570
  if (this.options.initialCountry === "auto" && intlTelInput.autoCountry) {
2568
2571
  this.defaultCountry = intlTelInput.autoCountry;
2569
- if (!this.telInput.value) {
2572
+ const hasSelectedCountryOrGlobe = this.selectedCountryData.iso2 || this.selectedCountryInner.classList.contains("iti__globe");
2573
+ if (!hasSelectedCountryOrGlobe) {
2570
2574
  this.setCountry(this.defaultCountry);
2571
2575
  }
2572
2576
  this.resolveAutoCountryPromise();
@@ -2744,7 +2748,7 @@ var intlTelInput = Object.assign(
2744
2748
  //* A map from instance ID to instance object.
2745
2749
  instances: {},
2746
2750
  loadUtils,
2747
- version: "23.0.10"
2751
+ version: "23.0.11"
2748
2752
  }
2749
2753
  );
2750
2754
  var intl_tel_input_default = intlTelInput;
@@ -1889,10 +1889,11 @@ var Iti = class {
1889
1889
  const val = useAttribute ? attributeValue : inputValue;
1890
1890
  const dialCode = this._getDialCode(val);
1891
1891
  const isRegionlessNanpNumber = isRegionlessNanp(val);
1892
- const { initialCountry } = this.options;
1892
+ const { initialCountry, geoIpLookup } = this.options;
1893
+ const isAutoCountry = initialCountry === "auto" && geoIpLookup;
1893
1894
  if (dialCode && !isRegionlessNanpNumber) {
1894
1895
  this._updateCountryFromNumber(val);
1895
- } else if (initialCountry !== "auto" || overrideAutoCountry) {
1896
+ } else if (!isAutoCountry || overrideAutoCountry) {
1896
1897
  const lowerInitialCountry = initialCountry ? initialCountry.toLowerCase() : "";
1897
1898
  const isValidInitialCountry = lowerInitialCountry && this._getCountryData(lowerInitialCountry, true);
1898
1899
  if (isValidInitialCountry) {
@@ -1971,18 +1972,20 @@ var Iti = class {
1971
1972
  }
1972
1973
  //* Init many requests: utils script / geo ip lookup.
1973
1974
  _initRequests() {
1974
- if (this.options.utilsScript && !intlTelInput.utils) {
1975
+ const { utilsScript, initialCountry, geoIpLookup } = this.options;
1976
+ if (utilsScript && !intlTelInput.utils) {
1975
1977
  if (intlTelInput.documentReady()) {
1976
- intlTelInput.loadUtils(this.options.utilsScript);
1978
+ intlTelInput.loadUtils(utilsScript);
1977
1979
  } else {
1978
1980
  window.addEventListener("load", () => {
1979
- intlTelInput.loadUtils(this.options.utilsScript);
1981
+ intlTelInput.loadUtils(utilsScript);
1980
1982
  });
1981
1983
  }
1982
1984
  } else {
1983
1985
  this.resolveUtilsScriptPromise();
1984
1986
  }
1985
- if (this.options.initialCountry === "auto" && !this.selectedCountryData.iso2) {
1987
+ const isAutoCountry = initialCountry === "auto" && geoIpLookup;
1988
+ if (isAutoCountry && !this.selectedCountryData.iso2) {
1986
1989
  this._loadAutoCountry();
1987
1990
  } else {
1988
1991
  this.resolveAutoCountryPromise();
@@ -2602,7 +2605,8 @@ var Iti = class {
2602
2605
  handleAutoCountry() {
2603
2606
  if (this.options.initialCountry === "auto" && intlTelInput.autoCountry) {
2604
2607
  this.defaultCountry = intlTelInput.autoCountry;
2605
- if (!this.telInput.value) {
2608
+ const hasSelectedCountryOrGlobe = this.selectedCountryData.iso2 || this.selectedCountryInner.classList.contains("iti__globe");
2609
+ if (!hasSelectedCountryOrGlobe) {
2606
2610
  this.setCountry(this.defaultCountry);
2607
2611
  }
2608
2612
  this.resolveAutoCountryPromise();
@@ -2780,7 +2784,7 @@ var intlTelInput = Object.assign(
2780
2784
  //* A map from instance ID to instance object.
2781
2785
  instances: {},
2782
2786
  loadUtils,
2783
- version: "23.0.10"
2787
+ version: "23.0.11"
2784
2788
  }
2785
2789
  );
2786
2790
  var intl_tel_input_default = intlTelInput;
@@ -1853,10 +1853,11 @@ var Iti = class {
1853
1853
  const val = useAttribute ? attributeValue : inputValue;
1854
1854
  const dialCode = this._getDialCode(val);
1855
1855
  const isRegionlessNanpNumber = isRegionlessNanp(val);
1856
- const { initialCountry } = this.options;
1856
+ const { initialCountry, geoIpLookup } = this.options;
1857
+ const isAutoCountry = initialCountry === "auto" && geoIpLookup;
1857
1858
  if (dialCode && !isRegionlessNanpNumber) {
1858
1859
  this._updateCountryFromNumber(val);
1859
- } else if (initialCountry !== "auto" || overrideAutoCountry) {
1860
+ } else if (!isAutoCountry || overrideAutoCountry) {
1860
1861
  const lowerInitialCountry = initialCountry ? initialCountry.toLowerCase() : "";
1861
1862
  const isValidInitialCountry = lowerInitialCountry && this._getCountryData(lowerInitialCountry, true);
1862
1863
  if (isValidInitialCountry) {
@@ -1935,18 +1936,20 @@ var Iti = class {
1935
1936
  }
1936
1937
  //* Init many requests: utils script / geo ip lookup.
1937
1938
  _initRequests() {
1938
- if (this.options.utilsScript && !intlTelInput.utils) {
1939
+ const { utilsScript, initialCountry, geoIpLookup } = this.options;
1940
+ if (utilsScript && !intlTelInput.utils) {
1939
1941
  if (intlTelInput.documentReady()) {
1940
- intlTelInput.loadUtils(this.options.utilsScript);
1942
+ intlTelInput.loadUtils(utilsScript);
1941
1943
  } else {
1942
1944
  window.addEventListener("load", () => {
1943
- intlTelInput.loadUtils(this.options.utilsScript);
1945
+ intlTelInput.loadUtils(utilsScript);
1944
1946
  });
1945
1947
  }
1946
1948
  } else {
1947
1949
  this.resolveUtilsScriptPromise();
1948
1950
  }
1949
- if (this.options.initialCountry === "auto" && !this.selectedCountryData.iso2) {
1951
+ const isAutoCountry = initialCountry === "auto" && geoIpLookup;
1952
+ if (isAutoCountry && !this.selectedCountryData.iso2) {
1950
1953
  this._loadAutoCountry();
1951
1954
  } else {
1952
1955
  this.resolveAutoCountryPromise();
@@ -2566,7 +2569,8 @@ var Iti = class {
2566
2569
  handleAutoCountry() {
2567
2570
  if (this.options.initialCountry === "auto" && intlTelInput.autoCountry) {
2568
2571
  this.defaultCountry = intlTelInput.autoCountry;
2569
- if (!this.telInput.value) {
2572
+ const hasSelectedCountryOrGlobe = this.selectedCountryData.iso2 || this.selectedCountryInner.classList.contains("iti__globe");
2573
+ if (!hasSelectedCountryOrGlobe) {
2570
2574
  this.setCountry(this.defaultCountry);
2571
2575
  }
2572
2576
  this.resolveAutoCountryPromise();
@@ -2744,7 +2748,7 @@ var intlTelInput = Object.assign(
2744
2748
  //* A map from instance ID to instance object.
2745
2749
  instances: {},
2746
2750
  loadUtils,
2747
- version: "23.0.10"
2751
+ version: "23.0.11"
2748
2752
  }
2749
2753
  );
2750
2754
  var intl_tel_input_default = intlTelInput;