intl-tel-input 25.13.1 → 25.13.3

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.
@@ -2236,6 +2236,7 @@ var buildClearIcon = (id2) => {
2236
2236
  var UI = class {
2237
2237
  constructor(input, options, id2) {
2238
2238
  this.highlightedItem = null;
2239
+ this.selectedItem = null;
2239
2240
  input.dataset.intlTelInputId = id2.toString();
2240
2241
  this.telInput = input;
2241
2242
  this.options = options;
@@ -2497,8 +2498,7 @@ var UI = class {
2497
2498
  for (let i = 0; i < this.countries.length; i++) {
2498
2499
  const c = this.countries[i];
2499
2500
  const liClass = buildClassNames({
2500
- [CLASSES.COUNTRY_ITEM]: true,
2501
- [CLASSES.HIGHLIGHT]: i === 0
2501
+ [CLASSES.COUNTRY_ITEM]: true
2502
2502
  });
2503
2503
  const listItem = createEl("li", {
2504
2504
  id: `iti-${this.id}__item-${c.iso2}`,
@@ -2601,17 +2601,15 @@ var UI = class {
2601
2601
  container.scrollTop = newScrollTop - heightDifference;
2602
2602
  }
2603
2603
  }
2604
- //* Remove highlighting from other list items and highlight the given item.
2604
+ //* Remove highlighting from the previous list item and highlight the new one.
2605
2605
  highlightListItem(listItem, shouldFocus) {
2606
2606
  const prevItem = this.highlightedItem;
2607
2607
  if (prevItem) {
2608
2608
  prevItem.classList.remove(CLASSES.HIGHLIGHT);
2609
- prevItem.setAttribute(ARIA.SELECTED, "false");
2610
2609
  }
2611
2610
  this.highlightedItem = listItem;
2612
2611
  if (this.highlightedItem) {
2613
2612
  this.highlightedItem.classList.add(CLASSES.HIGHLIGHT);
2614
- this.highlightedItem.setAttribute(ARIA.SELECTED, "true");
2615
2613
  if (this.options.countrySearch) {
2616
2614
  const activeDescendant = this.highlightedItem.getAttribute("id") || "";
2617
2615
  this.searchInput.setAttribute(ARIA.ACTIVE_DESCENDANT, activeDescendant);
@@ -2621,6 +2619,21 @@ var UI = class {
2621
2619
  this.highlightedItem.focus();
2622
2620
  }
2623
2621
  }
2622
+ updateSelectedItem(iso2) {
2623
+ if (this.selectedItem && this.selectedItem.dataset.countryCode !== iso2) {
2624
+ this.selectedItem.setAttribute(ARIA.SELECTED, "false");
2625
+ this.selectedItem = null;
2626
+ }
2627
+ if (iso2 && !this.selectedItem) {
2628
+ const newListItem = this.countryList.querySelector(
2629
+ `[data-country-code="${iso2}"]`
2630
+ );
2631
+ if (newListItem) {
2632
+ newListItem.setAttribute(ARIA.SELECTED, "true");
2633
+ this.selectedItem = newListItem;
2634
+ }
2635
+ }
2636
+ }
2624
2637
  //* Country search: Filter the country list to the given array of countries.
2625
2638
  filterCountries(matchedCountries) {
2626
2639
  this.countryList.innerHTML = "";
@@ -2672,6 +2685,7 @@ var UI = class {
2672
2685
  this.hiddenInput = null;
2673
2686
  this.hiddenInputCountry = null;
2674
2687
  this.highlightedItem = null;
2688
+ this.selectedItem = null;
2675
2689
  for (const c of this.countries) {
2676
2690
  delete c.nodeById[this.id];
2677
2691
  }
@@ -3600,11 +3614,14 @@ var Iti = class _Iti {
3600
3614
  }
3601
3615
  return null;
3602
3616
  }
3603
- //* Update the selected country, dial code (if separateDialCode), placeholder, title, and active list item.
3617
+ //* Update the selected country, dial code (if separateDialCode), placeholder, title, and selected list item.
3604
3618
  //* Note: called from _setInitialState, _updateCountryFromNumber, _selectListItem, setCountry.
3605
3619
  _setCountry(iso2) {
3606
- const { separateDialCode, showFlags, i18n } = this.options;
3620
+ const { separateDialCode, showFlags, i18n, allowDropdown } = this.options;
3607
3621
  const prevIso2 = this.selectedCountryData.iso2 || "";
3622
+ if (allowDropdown) {
3623
+ this.ui.updateSelectedItem(iso2);
3624
+ }
3608
3625
  this.selectedCountryData = iso2 ? this.countryByIso2.get(iso2) : {};
3609
3626
  if (this.selectedCountryData.iso2) {
3610
3627
  this.defaultCountry = this.selectedCountryData.iso2;
@@ -3711,11 +3728,12 @@ var Iti = class _Iti {
3711
3728
  }
3712
3729
  this.ui.dropdownContent.classList.add(CLASSES.HIDE);
3713
3730
  this.ui.selectedCountry.setAttribute(ARIA.EXPANDED, "false");
3714
- if (this.ui.highlightedItem) {
3715
- this.ui.highlightedItem.setAttribute(ARIA.SELECTED, "false");
3716
- }
3717
3731
  if (this.options.countrySearch) {
3718
3732
  this.ui.searchInput.removeAttribute(ARIA.ACTIVE_DESCENDANT);
3733
+ if (this.ui.highlightedItem) {
3734
+ this.ui.highlightedItem.classList.remove(CLASSES.HIGHLIGHT);
3735
+ this.ui.highlightedItem = null;
3736
+ }
3719
3737
  }
3720
3738
  this.ui.dropdownArrow.classList.remove(CLASSES.ARROW_UP);
3721
3739
  this.dropdownAbortController.abort();
@@ -4052,7 +4070,7 @@ var intlTelInput = Object.assign(
4052
4070
  attachUtils,
4053
4071
  startedLoadingUtilsScript: false,
4054
4072
  startedLoadingAutoCountry: false,
4055
- version: "25.13.1"
4073
+ version: "25.13.3"
4056
4074
  }
4057
4075
  );
4058
4076
  var intl_tel_input_default = intlTelInput;