intl-tel-input 19.5.3 → 19.5.5

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.
@@ -24304,9 +24304,9 @@ var rt = (c, p, g, m) => {
24304
24304
  return c;
24305
24305
  };
24306
24306
  var at = (c, p, g) => (g = c != null ? X(it(c)) : {}, rt(p || !c || !c.__esModule ? V(g, "default", { value: c, enumerable: true }) : g, c));
24307
- var H = ot((dt, F) => {
24307
+ var H = ot((dt, N) => {
24308
24308
  (function(c) {
24309
- typeof F == "object" && F.exports ? F.exports = c() : window.intlTelInput = c();
24309
+ typeof N == "object" && N.exports ? N.exports = c() : window.intlTelInput = c();
24310
24310
  })(function(c) {
24311
24311
  "use strict";
24312
24312
  return function() {
@@ -24513,12 +24513,12 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
24513
24513
  var f = this._createEl("div", { class: v });
24514
24514
  this.telInput.parentNode.insertBefore(f, this.telInput);
24515
24515
  var I = e || o || i;
24516
- if (I && (this.flagsContainer = this._createEl("div", { class: "iti__flag-container" }, f)), f.appendChild(this.telInput), I && (this.selectedFlag = this._createEl("div", _({ class: "iti__selected-flag" }, e && { role: "combobox", "aria-haspopup": "listbox", "aria-controls": "iti-".concat(this.id, "__country-listbox"), "aria-expanded": "false", "aria-label": this.options.i18n.selectedCountryAriaLabel || "Selected country" }), this.flagsContainer)), o && (this.selectedFlagInner = this._createEl("div", { class: "iti__flag iti__globe" }, this.selectedFlag)), this.selectedFlag && this.telInput.disabled && this.selectedFlag.setAttribute("aria-disabled", "true"), i && (this.selectedDialCode = this._createEl("div", { class: "iti__selected-dial-code" }, this.selectedFlag)), e) {
24516
+ if (I && (this.flagsContainer = this._createEl("div", { class: "iti__flag-container" }, f)), f.appendChild(this.telInput), I && (this.selectedFlag = this._createEl("div", _({ class: "iti__selected-flag" }, e && { role: "combobox", "aria-haspopup": "listbox", "aria-controls": "iti-".concat(this.id, "__country-listbox"), "aria-expanded": "false", "aria-label": this.options.i18n.selectedCountryAriaLabel || "Selected country" }), this.flagsContainer)), o && (this.selectedFlagInner = this._createEl("div", { class: "iti__flag" }, this.selectedFlag)), this.selectedFlag && this.telInput.disabled && this.selectedFlag.setAttribute("aria-disabled", "true"), i && (this.selectedDialCode = this._createEl("div", { class: "iti__selected-dial-code" }, this.selectedFlag)), e) {
24517
24517
  this.telInput.disabled || this.selectedFlag.setAttribute("tabindex", "0"), this.dropdownArrow = this._createEl("div", { class: "iti__arrow" }, this.selectedFlag);
24518
24518
  var $ = u ? "" : "iti--flexible-dropdown-width";
24519
24519
  if (this.dropdownContent = this._createEl("div", { class: "iti__dropdown-content iti__hide ".concat($) }), y && (this.searchInput = this._createEl("input", { type: "text", class: "iti__search-input", placeholder: this.options.i18n.searchPlaceholder || "Search" }, this.dropdownContent)), this.countryList = this._createEl("ul", { class: "iti__country-list", id: "iti-".concat(this.id, "__country-listbox"), role: "listbox", "aria-label": this.options.i18n.countryListAriaLabel || "List of countries" }, this.dropdownContent), this.preferredCountries.length && !y && (this._appendListItems(this.preferredCountries, "iti__preferred", true), this._createEl("li", { class: "iti__divider", "aria-hidden": "true" }, this.countryList)), this._appendListItems(this.countries, "iti__standard"), l) {
24520
- var N = "iti iti--container";
24521
- h ? N += " iti--fullscreen-popup" : N += " iti--inline-dropdown", y && (N += " iti--country-search"), this.dropdown = this._createEl("div", { class: N }), this.dropdown.appendChild(this.dropdownContent);
24520
+ var F = "iti iti--container";
24521
+ h ? F += " iti--fullscreen-popup" : F += " iti--inline-dropdown", y && (F += " iti--country-search"), this.dropdown = this._createEl("div", { class: F }), this.dropdown.appendChild(this.dropdownContent);
24522
24522
  } else
24523
24523
  this.flagsContainer.appendChild(this.dropdownContent);
24524
24524
  }
@@ -24541,7 +24541,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
24541
24541
  this._updateFlagFromNumber(r);
24542
24542
  else if (h !== "auto" || t) {
24543
24543
  var f = h ? h.toLowerCase() : "", I = f && this._getCountryData(f, true);
24544
- I ? this._setFlag(f) : s && l ? this._setFlag("us") : v && (this.defaultCountry = this.preferredCountries.length ? this.preferredCountries[0].iso2 : this.countries[0].iso2, r || this._setFlag(this.defaultCountry)), !r && y && (this.telInput.value = "+".concat(this.selectedCountryData.dialCode));
24544
+ I ? this._setFlag(f) : s && l ? this._setFlag("us") : v && !r ? (this.defaultCountry = this.preferredCountries.length ? this.preferredCountries[0].iso2 : this.countries[0].iso2, this._setFlag(this.defaultCountry)) : this._setFlag(), !r && y && (this.telInput.value = "+".concat(this.selectedCountryData.dialCode));
24545
24545
  }
24546
24546
  r && this._updateValFromNumber(r);
24547
24547
  } }, { key: "_initListeners", value: function() {
@@ -24903,7 +24903,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
24903
24903
  z(a);
24904
24904
  }
24905
24905
  return null;
24906
- }, S.defaults = K, S.version = "19.5.3", function(a, n) {
24906
+ }, S.defaults = K, S.version = "19.5.5", function(a, n) {
24907
24907
  var t = new Z(a, n);
24908
24908
  return t._init(), a.setAttribute("data-intl-tel-input-id", t.id), window.intlTelInputGlobals.instances[t.id] = t, t;
24909
24909
  };
@@ -24304,9 +24304,9 @@ var rt = (c, p, g, m) => {
24304
24304
  return c;
24305
24305
  };
24306
24306
  var at = (c, p, g) => (g = c != null ? X(it(c)) : {}, rt(p || !c || !c.__esModule ? V(g, "default", { value: c, enumerable: true }) : g, c));
24307
- var H = ot((dt, F) => {
24307
+ var H = ot((dt, N) => {
24308
24308
  (function(c) {
24309
- typeof F == "object" && F.exports ? F.exports = c() : window.intlTelInput = c();
24309
+ typeof N == "object" && N.exports ? N.exports = c() : window.intlTelInput = c();
24310
24310
  })(function(c) {
24311
24311
  "use strict";
24312
24312
  return function() {
@@ -24513,12 +24513,12 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
24513
24513
  var f = this._createEl("div", { class: v });
24514
24514
  this.telInput.parentNode.insertBefore(f, this.telInput);
24515
24515
  var I = e || o || i;
24516
- if (I && (this.flagsContainer = this._createEl("div", { class: "iti__flag-container" }, f)), f.appendChild(this.telInput), I && (this.selectedFlag = this._createEl("div", _({ class: "iti__selected-flag" }, e && { role: "combobox", "aria-haspopup": "listbox", "aria-controls": "iti-".concat(this.id, "__country-listbox"), "aria-expanded": "false", "aria-label": this.options.i18n.selectedCountryAriaLabel || "Selected country" }), this.flagsContainer)), o && (this.selectedFlagInner = this._createEl("div", { class: "iti__flag iti__globe" }, this.selectedFlag)), this.selectedFlag && this.telInput.disabled && this.selectedFlag.setAttribute("aria-disabled", "true"), i && (this.selectedDialCode = this._createEl("div", { class: "iti__selected-dial-code" }, this.selectedFlag)), e) {
24516
+ if (I && (this.flagsContainer = this._createEl("div", { class: "iti__flag-container" }, f)), f.appendChild(this.telInput), I && (this.selectedFlag = this._createEl("div", _({ class: "iti__selected-flag" }, e && { role: "combobox", "aria-haspopup": "listbox", "aria-controls": "iti-".concat(this.id, "__country-listbox"), "aria-expanded": "false", "aria-label": this.options.i18n.selectedCountryAriaLabel || "Selected country" }), this.flagsContainer)), o && (this.selectedFlagInner = this._createEl("div", { class: "iti__flag" }, this.selectedFlag)), this.selectedFlag && this.telInput.disabled && this.selectedFlag.setAttribute("aria-disabled", "true"), i && (this.selectedDialCode = this._createEl("div", { class: "iti__selected-dial-code" }, this.selectedFlag)), e) {
24517
24517
  this.telInput.disabled || this.selectedFlag.setAttribute("tabindex", "0"), this.dropdownArrow = this._createEl("div", { class: "iti__arrow" }, this.selectedFlag);
24518
24518
  var $ = u ? "" : "iti--flexible-dropdown-width";
24519
24519
  if (this.dropdownContent = this._createEl("div", { class: "iti__dropdown-content iti__hide ".concat($) }), y && (this.searchInput = this._createEl("input", { type: "text", class: "iti__search-input", placeholder: this.options.i18n.searchPlaceholder || "Search" }, this.dropdownContent)), this.countryList = this._createEl("ul", { class: "iti__country-list", id: "iti-".concat(this.id, "__country-listbox"), role: "listbox", "aria-label": this.options.i18n.countryListAriaLabel || "List of countries" }, this.dropdownContent), this.preferredCountries.length && !y && (this._appendListItems(this.preferredCountries, "iti__preferred", true), this._createEl("li", { class: "iti__divider", "aria-hidden": "true" }, this.countryList)), this._appendListItems(this.countries, "iti__standard"), l) {
24520
- var N = "iti iti--container";
24521
- h ? N += " iti--fullscreen-popup" : N += " iti--inline-dropdown", y && (N += " iti--country-search"), this.dropdown = this._createEl("div", { class: N }), this.dropdown.appendChild(this.dropdownContent);
24520
+ var F = "iti iti--container";
24521
+ h ? F += " iti--fullscreen-popup" : F += " iti--inline-dropdown", y && (F += " iti--country-search"), this.dropdown = this._createEl("div", { class: F }), this.dropdown.appendChild(this.dropdownContent);
24522
24522
  } else
24523
24523
  this.flagsContainer.appendChild(this.dropdownContent);
24524
24524
  }
@@ -24541,7 +24541,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
24541
24541
  this._updateFlagFromNumber(r);
24542
24542
  else if (h !== "auto" || t) {
24543
24543
  var f = h ? h.toLowerCase() : "", I = f && this._getCountryData(f, true);
24544
- I ? this._setFlag(f) : s && l ? this._setFlag("us") : v && (this.defaultCountry = this.preferredCountries.length ? this.preferredCountries[0].iso2 : this.countries[0].iso2, r || this._setFlag(this.defaultCountry)), !r && y && (this.telInput.value = "+".concat(this.selectedCountryData.dialCode));
24544
+ I ? this._setFlag(f) : s && l ? this._setFlag("us") : v && !r ? (this.defaultCountry = this.preferredCountries.length ? this.preferredCountries[0].iso2 : this.countries[0].iso2, this._setFlag(this.defaultCountry)) : this._setFlag(), !r && y && (this.telInput.value = "+".concat(this.selectedCountryData.dialCode));
24545
24545
  }
24546
24546
  r && this._updateValFromNumber(r);
24547
24547
  } }, { key: "_initListeners", value: function() {
@@ -24903,7 +24903,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
24903
24903
  z(a);
24904
24904
  }
24905
24905
  return null;
24906
- }, S.defaults = K, S.version = "19.5.3", function(a, n) {
24906
+ }, S.defaults = K, S.version = "19.5.5", function(a, n) {
24907
24907
  var t = new Z(a, n);
24908
24908
  return t._init(), a.setAttribute("data-intl-tel-input-id", t.id), window.intlTelInputGlobals.instances[t.id] = t, t;
24909
24909
  };
@@ -436,7 +436,7 @@ class Iti {
436
436
  if (showFlags) {
437
437
  this.selectedFlagInner = this._createEl(
438
438
  "div",
439
- { class: "iti__flag iti__globe" },
439
+ { class: "iti__flag" },
440
440
  this.selectedFlag
441
441
  );
442
442
  }
@@ -631,14 +631,15 @@ class Iti {
631
631
  if (dialCode && isRegionlessNanp) {
632
632
  // has intl dial code, is regionless nanp, and no initialCountry, so default to US
633
633
  this._setFlag("us");
634
- } else if (defaultToFirstCountry) {
634
+ } else if (defaultToFirstCountry && !val) {
635
635
  // no dial code and no initialCountry, so default to first in list
636
636
  this.defaultCountry = this.preferredCountries.length
637
637
  ? this.preferredCountries[0].iso2
638
638
  : this.countries[0].iso2;
639
- if (!val) {
640
- this._setFlag(this.defaultCountry);
641
- }
639
+ this._setFlag(this.defaultCountry);
640
+ } else {
641
+ // display the empty state (globe icon)
642
+ this._setFlag();
642
643
  }
643
644
  }
644
645
 
package/src/js/utils.js CHANGED
@@ -129,7 +129,17 @@ const isPossibleNumber = (number, countryCode) => {
129
129
  const numberObj = phoneUtil.parseAndKeepRawInput(number, countryCode);
130
130
  // can't use phoneUtil.isPossibleNumber directly as it accepts IS_POSSIBLE_LOCAL_ONLY numbers e.g. local numbers that are much shorter
131
131
  const result = phoneUtil.isPossibleNumberWithReason(numberObj);
132
- return result === i18n.phonenumbers.PhoneNumberUtil.ValidationResult.IS_POSSIBLE;
132
+ const isPossible = result === i18n.phonenumbers.PhoneNumberUtil.ValidationResult.IS_POSSIBLE;
133
+
134
+ // custom validation for UK mobile numbers
135
+ // because libphonenumber returns IS_POSSIBLE (rather than IS_POSSIBLE_LOCAL_ONLY) for 0740012 which is not possible
136
+ let customValidation = true;
137
+ const nationalNumber = numberObj.getNationalNumber().toString();
138
+ if (countryCode === 'gb' && nationalNumber.charAt(0) === '7') {
139
+ customValidation = nationalNumber.length === 10;
140
+ }
141
+
142
+ return isPossible && customValidation;
133
143
  } catch (e) {
134
144
  return false;
135
145
  }
@@ -34,10 +34,9 @@ describe("isValidNumber:", function() {
34
34
  expect(iti.isValidNumber()).toBeFalsy();
35
35
  });
36
36
 
37
- // guess this is a quirk of UK phone numbers that some valid ones are only 10 digits (e.g. 0773312345)
38
- it("returns true for: invalid (too short by 1 digit) intl number", function() {
37
+ it("returns false for: invalid (too short by 1 digit) intl number", function() {
39
38
  iti.setNumber("+44 7733 12345");
40
- expect(iti.isValidNumber()).toBeTruthy();
39
+ expect(iti.isValidNumber()).toBeFalsy();
41
40
  });
42
41
 
43
42
  it("returns false for: invalid (too long) intl number", function() {