intl-tel-input 24.2.1 → 24.3.1

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.
@@ -1,5 +1,5 @@
1
1
  /*
2
- * International Telephone Input v24.2.1
2
+ * International Telephone Input v24.3.1
3
3
  * https://github.com/jackocnr/intl-tel-input.git
4
4
  * Licensed under the MIT license
5
5
  */
@@ -1762,8 +1762,10 @@ var factoryOutput = (() => {
1762
1762
  if (this.options.useFullscreenPopup) {
1763
1763
  this.options.fixDropdownWidth = false;
1764
1764
  }
1765
+ if (this.options.onlyCountries.length === 1) {
1766
+ this.options.initialCountry = this.options.onlyCountries[0];
1767
+ }
1765
1768
  if (this.options.separateDialCode) {
1766
- this.options.allowDropdown = true;
1767
1769
  this.options.nationalMode = false;
1768
1770
  this.options.countrySearch = true;
1769
1771
  }
@@ -1775,6 +1777,8 @@ var factoryOutput = (() => {
1775
1777
  }
1776
1778
  this.isAndroid = typeof navigator !== "undefined" ? /Android/i.test(navigator.userAgent) : false;
1777
1779
  this.isRTL = !!this.telInput.closest("[dir=rtl]");
1780
+ const showOnDefaultSide = this.options.allowDropdown || this.options.separateDialCode;
1781
+ this.showSelectedCountryOnLeft = this.isRTL ? !showOnDefaultSide : showOnDefaultSide;
1778
1782
  if (this.options.separateDialCode) {
1779
1783
  if (this.isRTL) {
1780
1784
  this.originalPaddingRight = this.telInput.style.paddingRight;
@@ -1938,10 +1942,13 @@ var factoryOutput = (() => {
1938
1942
  }
1939
1943
  const wrapper = createEl("div", { class: parentClass });
1940
1944
  this.telInput.parentNode?.insertBefore(wrapper, this.telInput);
1941
- if (allowDropdown || showFlags) {
1945
+ if (allowDropdown || showFlags || separateDialCode) {
1942
1946
  this.countryContainer = createEl(
1943
1947
  "div",
1944
- { class: "iti__country-container" },
1948
+ {
1949
+ class: "iti__country-container",
1950
+ style: this.showSelectedCountryOnLeft ? "left: 0" : "right: 0"
1951
+ },
1945
1952
  wrapper
1946
1953
  );
1947
1954
  if (allowDropdown) {
@@ -2046,6 +2053,7 @@ var factoryOutput = (() => {
2046
2053
  }
2047
2054
  }
2048
2055
  wrapper.appendChild(this.telInput);
2056
+ this._updateInputPadding();
2049
2057
  if (hiddenInput) {
2050
2058
  const telInputName = this.telInput.getAttribute("name") || "";
2051
2059
  const names = hiddenInput(telInputName);
@@ -2232,25 +2240,25 @@ var factoryOutput = (() => {
2232
2240
  }
2233
2241
  }
2234
2242
  }
2243
+ _openDropdownWithPlus() {
2244
+ this._openDropdown();
2245
+ this.searchInput.value = "+";
2246
+ this._filterCountries("", true);
2247
+ }
2235
2248
  //* Initialize the tel input listeners.
2236
2249
  _initTelInputListeners() {
2237
- const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay } = this.options;
2250
+ const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay, allowDropdown } = this.options;
2238
2251
  let userOverrideFormatting = false;
2239
2252
  if (/\p{L}/u.test(this.telInput.value)) {
2240
2253
  userOverrideFormatting = true;
2241
2254
  }
2242
- const openDropdownWithPlus = () => {
2243
- this._openDropdown();
2244
- this.searchInput.value = "+";
2245
- this._filterCountries("", true);
2246
- };
2247
2255
  this._handleInputEvent = (e) => {
2248
- if (this.isAndroid && e?.data === "+" && separateDialCode) {
2256
+ if (this.isAndroid && e?.data === "+" && separateDialCode && allowDropdown) {
2249
2257
  const currentCaretPos = this.telInput.selectionStart || 0;
2250
2258
  const valueBeforeCaret = this.telInput.value.substring(0, currentCaretPos - 1);
2251
2259
  const valueAfterCaret = this.telInput.value.substring(currentCaretPos);
2252
2260
  this.telInput.value = valueBeforeCaret + valueAfterCaret;
2253
- openDropdownWithPlus();
2261
+ this._openDropdownWithPlus();
2254
2262
  return;
2255
2263
  }
2256
2264
  if (this._updateCountryFromNumber(this.telInput.value)) {
@@ -2279,15 +2287,15 @@ var factoryOutput = (() => {
2279
2287
  if (strictMode || separateDialCode) {
2280
2288
  this._handleKeydownEvent = (e) => {
2281
2289
  if (e.key && e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {
2282
- if (separateDialCode && e.key === "+") {
2290
+ if (separateDialCode && allowDropdown && e.key === "+") {
2283
2291
  e.preventDefault();
2284
- openDropdownWithPlus();
2292
+ this._openDropdownWithPlus();
2285
2293
  return;
2286
2294
  }
2287
2295
  if (strictMode) {
2288
2296
  const isInitialPlus = this.telInput.selectionStart === 0 && e.key === "+";
2289
2297
  const isNumeric = /^[0-9]$/.test(e.key);
2290
- const isAllowedChar = isInitialPlus || isNumeric;
2298
+ const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
2291
2299
  const fullNumber = this._getFullNumber();
2292
2300
  const coreNumber = intlTelInput.utils.getCoreNumber(fullNumber, this.selectedCountryData.iso2);
2293
2301
  const hasReachedMaxLength = this.maxCoreNumberLength && coreNumber.length >= this.maxCoreNumberLength;
@@ -2622,18 +2630,24 @@ var factoryOutput = (() => {
2622
2630
  if (separateDialCode) {
2623
2631
  const dialCode = this.selectedCountryData.dialCode ? `+${this.selectedCountryData.dialCode}` : "";
2624
2632
  this.selectedDialCode.innerHTML = dialCode;
2625
- const selectedCountryWidth = this.selectedCountry.offsetWidth || this._getHiddenSelectedCountryWidth();
2626
- const inputPadding = selectedCountryWidth + 8;
2627
- if (this.isRTL) {
2628
- this.telInput.style.paddingRight = `${inputPadding}px`;
2629
- } else {
2630
- this.telInput.style.paddingLeft = `${inputPadding}px`;
2631
- }
2633
+ this._updateInputPadding();
2632
2634
  }
2633
2635
  this._updatePlaceholder();
2634
2636
  this._updateMaxLength();
2635
2637
  return prevCountry.iso2 !== iso2;
2636
2638
  }
2639
+ //* Update the input padding to make space for the selected country/dial code.
2640
+ _updateInputPadding() {
2641
+ if (this.selectedCountry) {
2642
+ const selectedCountryWidth = this.selectedCountry.offsetWidth || this._getHiddenSelectedCountryWidth();
2643
+ const inputPadding = selectedCountryWidth + 6;
2644
+ if (this.showSelectedCountryOnLeft) {
2645
+ this.telInput.style.paddingLeft = `${inputPadding}px`;
2646
+ } else {
2647
+ this.telInput.style.paddingRight = `${inputPadding}px`;
2648
+ }
2649
+ }
2650
+ }
2637
2651
  //* Update the maximum valid number length for the currently selected country.
2638
2652
  _updateMaxLength() {
2639
2653
  const { strictMode, placeholderNumberType, validationNumberType } = this.options;
@@ -3083,7 +3097,7 @@ var factoryOutput = (() => {
3083
3097
  //* A map from instance ID to instance object.
3084
3098
  instances: {},
3085
3099
  loadUtils,
3086
- version: "24.2.1"
3100
+ version: "24.3.1"
3087
3101
  }
3088
3102
  );
3089
3103
  var intl_tel_input_default = intlTelInput;