intl-tel-input 19.2.19 → 19.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.
@@ -18,7 +18,6 @@ const defaults = {
18
18
  // whether or not to allow the dropdown
19
19
  allowDropdown: true,
20
20
  // auto insert dial code (A) on init, (B) on user selecting a country, (C) on calling setCountry
21
- // also listen for blur/submit and auto remove dial code if that's all there is
22
21
  autoInsertDialCode: false,
23
22
  // add a placeholder in the input with an example number for the selected country
24
23
  autoPlaceholder: "polite",
@@ -28,6 +27,8 @@ const defaults = {
28
27
  containerClass: "",
29
28
  // modify the auto placeholder
30
29
  customPlaceholder: null,
30
+ // by default, initialise with the first country in the list selected (if no country set via the initial value or initialCountry option)
31
+ defaultToFirstCountry: true,
31
32
  // append menu to specified element
32
33
  dropdownContainer: null,
33
34
  // don't display these countries
@@ -582,22 +583,23 @@ class Iti {
582
583
  const val = useAttribute ? attributeValue : inputValue;
583
584
  const dialCode = this._getDialCode(val);
584
585
  const isRegionlessNanp = this._isRegionlessNanp(val);
585
- const { initialCountry, autoInsertDialCode } = this.options;
586
+ const { initialCountry, autoInsertDialCode, defaultToFirstCountry } = this.options;
586
587
 
587
588
  // if we already have a dial code, and it's not a regionlessNanp, we can go ahead and set the
588
589
  // flag, else fall back to the default country
589
590
  if (dialCode && !isRegionlessNanp) {
590
591
  this._updateFlagFromNumber(val);
591
592
  } else if (initialCountry !== "auto" || overrideAutoCountry) {
592
- const isValidInitialCountry = initialCountry && !!this._getCountryData(initialCountry, true);
593
+ const lowerInitialCountry = initialCountry ? initialCountry.toLowerCase() : "";
594
+ const isValidInitialCountry = lowerInitialCountry && this._getCountryData(lowerInitialCountry, true);
593
595
  // see if we should select a flag
594
596
  if (isValidInitialCountry) {
595
- this._setFlag(initialCountry.toLowerCase());
597
+ this._setFlag(lowerInitialCountry);
596
598
  } else {
597
599
  if (dialCode && isRegionlessNanp) {
598
600
  // has intl dial code, is regionless nanp, and no initialCountry, so default to US
599
601
  this._setFlag("us");
600
- } else {
602
+ } else if (defaultToFirstCountry) {
601
603
  // no dial code and no initialCountry, so default to first in list
602
604
  this.defaultCountry = this.preferredCountries.length
603
605
  ? this.preferredCountries[0].iso2
@@ -750,8 +752,8 @@ class Iti {
750
752
  this.options.geoIpLookup(
751
753
  (countryCode = "") => {
752
754
  const lowerCountryCode = countryCode.toLowerCase();
753
- const isValid = !!this._getCountryData(lowerCountryCode, true);
754
- if (isValid) {
755
+ const isValidCountryCode = lowerCountryCode && this._getCountryData(lowerCountryCode, true);
756
+ if (isValidCountryCode) {
755
757
  window.intlTelInputGlobals.autoCountry = lowerCountryCode;
756
758
  // tell all instances the auto country is ready
757
759
  // TODO: this should just be the current instances