intl-tel-input 23.3.2 → 23.4.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intl-tel-input",
3
- "version": "23.3.2",
3
+ "version": "23.4.1",
4
4
  "description": "A JavaScript plugin for entering and validating international telephone numbers",
5
5
  "keywords": [
6
6
  "international",
@@ -24,6 +24,7 @@
24
24
  "license": "MIT",
25
25
  "author": "Jack O'Connor (http://jackocnr.com)",
26
26
  "devDependencies": {
27
+ "@testing-library/jest-dom": "^6.4.6",
27
28
  "@testing-library/user-event": "^14.5.2",
28
29
  "@types/react": "^18.2.74",
29
30
  "@types/react-dom": "^18.2.24",
package/react/README.md CHANGED
@@ -29,7 +29,7 @@ import "intl-tel-input/styles";
29
29
 
30
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.
31
31
 
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.3.2/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.4.1/build/js/utils.js"`.
33
33
 
34
34
  ## Props
35
35
  Here's a list of all of the current props you can pass to the IntlTelInput react component.
@@ -1397,6 +1397,8 @@ var defaults = {
1397
1397
  containerClass: "",
1398
1398
  //* The order of the countries in the dropdown. Defaults to alphabetical.
1399
1399
  countryOrder: null,
1400
+ //* Add a country search input at the top of the dropdown.
1401
+ countrySearch: true,
1400
1402
  //* Modify the auto placeholder.
1401
1403
  customPlaceholder: null,
1402
1404
  //* Append menu to specified element.
@@ -1519,6 +1521,7 @@ var Iti = class {
1519
1521
  if (this.options.separateDialCode) {
1520
1522
  this.options.allowDropdown = true;
1521
1523
  this.options.nationalMode = false;
1524
+ this.options.countrySearch = true;
1522
1525
  }
1523
1526
  if (!this.options.showFlags && !this.options.separateDialCode) {
1524
1527
  this.options.nationalMode = false;
@@ -1528,6 +1531,13 @@ var Iti = class {
1528
1531
  }
1529
1532
  this.isAndroid = typeof navigator !== "undefined" ? /Android/i.test(navigator.userAgent) : false;
1530
1533
  this.isRTL = !!this.telInput.closest("[dir=rtl]");
1534
+ if (this.options.separateDialCode) {
1535
+ if (this.isRTL) {
1536
+ this.originalPaddingRight = this.telInput.style.paddingRight;
1537
+ } else {
1538
+ this.originalPaddingLeft = this.telInput.style.paddingLeft;
1539
+ }
1540
+ }
1531
1541
  this.options.i18n = { ...en_default, ...this.options.i18n };
1532
1542
  const autoCountryPromise = new Promise((resolve, reject) => {
1533
1543
  this.resolveAutoCountryPromise = resolve;
@@ -1671,6 +1681,7 @@ var Iti = class {
1671
1681
  dropdownContainer,
1672
1682
  fixDropdownWidth,
1673
1683
  useFullscreenPopup,
1684
+ countrySearch,
1674
1685
  i18n
1675
1686
  } = this.options;
1676
1687
  let parentClass = "iti";
@@ -1747,26 +1758,28 @@ var Iti = class {
1747
1758
  id: `iti-${this.id}__dropdown-content`,
1748
1759
  class: `iti__dropdown-content iti__hide ${extraClasses}`
1749
1760
  });
1750
- this.searchInput = createEl(
1751
- "input",
1752
- {
1753
- type: "text",
1754
- class: "iti__search-input",
1755
- placeholder: i18n.searchPlaceholder,
1756
- role: "combobox",
1757
- "aria-expanded": "true",
1758
- "aria-label": i18n.searchPlaceholder,
1759
- "aria-controls": `iti-${this.id}__country-listbox`,
1760
- "aria-autocomplete": "list",
1761
- "autocomplete": "off"
1762
- },
1763
- this.dropdownContent
1764
- );
1765
- this.searchResultsA11yText = createEl(
1766
- "span",
1767
- { class: "iti__a11y-text" },
1768
- this.dropdownContent
1769
- );
1761
+ if (countrySearch) {
1762
+ this.searchInput = createEl(
1763
+ "input",
1764
+ {
1765
+ type: "text",
1766
+ class: "iti__search-input",
1767
+ placeholder: i18n.searchPlaceholder,
1768
+ role: "combobox",
1769
+ "aria-expanded": "true",
1770
+ "aria-label": i18n.searchPlaceholder,
1771
+ "aria-controls": `iti-${this.id}__country-listbox`,
1772
+ "aria-autocomplete": "list",
1773
+ "autocomplete": "off"
1774
+ },
1775
+ this.dropdownContent
1776
+ );
1777
+ this.searchResultsA11yText = createEl(
1778
+ "span",
1779
+ { class: "iti__a11y-text" },
1780
+ this.dropdownContent
1781
+ );
1782
+ }
1770
1783
  this.countryList = createEl(
1771
1784
  "ul",
1772
1785
  {
@@ -1777,8 +1790,10 @@ var Iti = class {
1777
1790
  },
1778
1791
  this.dropdownContent
1779
1792
  );
1780
- this._appendListItems(this.countries, "iti__standard");
1781
- this._updateSearchResultsText();
1793
+ this._appendListItems();
1794
+ if (countrySearch) {
1795
+ this._updateSearchResultsText();
1796
+ }
1782
1797
  if (dropdownContainer) {
1783
1798
  let dropdownClasses = "iti iti--container";
1784
1799
  if (useFullscreenPopup) {
@@ -1813,15 +1828,16 @@ var Iti = class {
1813
1828
  }
1814
1829
  }
1815
1830
  }
1816
- //* For each of the passed countries: add a country <li> to the countryList <ul> container.
1817
- _appendListItems(countries, className) {
1818
- for (let i = 0; i < countries.length; i++) {
1819
- const c = countries[i];
1831
+ //* For each country: add a country list item <li> to the countryList <ul> container.
1832
+ _appendListItems() {
1833
+ for (let i = 0; i < this.countries.length; i++) {
1834
+ const c = this.countries[i];
1835
+ const extraClass = i === 0 ? "iti__highlight" : "";
1820
1836
  const listItem = createEl(
1821
1837
  "li",
1822
1838
  {
1823
1839
  id: `iti-${this.id}__item-${c.iso2}`,
1824
- class: `iti__country ${className}`,
1840
+ class: `iti__country ${extraClass}`,
1825
1841
  tabindex: "-1",
1826
1842
  role: "option",
1827
1843
  "data-dial-code": c.dialCode,
@@ -2062,24 +2078,26 @@ var Iti = class {
2062
2078
  }
2063
2079
  //* Open the dropdown.
2064
2080
  _openDropdown() {
2065
- const { fixDropdownWidth } = this.options;
2081
+ const { fixDropdownWidth, countrySearch } = this.options;
2066
2082
  if (fixDropdownWidth) {
2067
2083
  this.dropdownContent.style.width = `${this.telInput.offsetWidth}px`;
2068
2084
  }
2069
2085
  this.dropdownContent.classList.remove("iti__hide");
2070
2086
  this.selectedCountry.setAttribute("aria-expanded", "true");
2071
2087
  this._setDropdownPosition();
2072
- const firstCountryItem = this.countryList.firstElementChild;
2073
- if (firstCountryItem) {
2074
- this._highlightListItem(firstCountryItem, false);
2075
- this.countryList.scrollTop = 0;
2088
+ if (countrySearch) {
2089
+ const firstCountryItem = this.countryList.firstElementChild;
2090
+ if (firstCountryItem) {
2091
+ this._highlightListItem(firstCountryItem, false);
2092
+ this.countryList.scrollTop = 0;
2093
+ }
2094
+ this.searchInput.focus();
2076
2095
  }
2077
- this.searchInput.focus();
2078
2096
  this._bindDropdownListeners();
2079
2097
  this.dropdownArrow.classList.add("iti__arrow--up");
2080
2098
  this._trigger("open:countrydropdown");
2081
2099
  }
2082
- //* Decide if should position dropdown above or below input (depends on position within viewport, and scroll).
2100
+ //* Set the dropdown position
2083
2101
  _setDropdownPosition() {
2084
2102
  if (this.options.dropdownContainer) {
2085
2103
  this.options.dropdownContainer.appendChild(this.dropdown);
@@ -2125,6 +2143,8 @@ var Iti = class {
2125
2143
  "click",
2126
2144
  this._handleClickOffToClose
2127
2145
  );
2146
+ let query = "";
2147
+ let queryTimer = null;
2128
2148
  this._handleKeydownOnDropdown = (e) => {
2129
2149
  if (["ArrowUp", "ArrowDown", "Enter", "Escape"].includes(e.key)) {
2130
2150
  e.preventDefault();
@@ -2137,29 +2157,56 @@ var Iti = class {
2137
2157
  this._closeDropdown();
2138
2158
  }
2139
2159
  }
2140
- };
2141
- document.addEventListener("keydown", this._handleKeydownOnDropdown);
2142
- const doFilter = () => {
2143
- const inputQuery = this.searchInput.value.trim();
2144
- if (inputQuery) {
2145
- this._filterCountries(inputQuery);
2146
- } else {
2147
- this._filterCountries("", true);
2160
+ if (!this.options.countrySearch && /^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(e.key)) {
2161
+ e.stopPropagation();
2162
+ if (queryTimer) {
2163
+ clearTimeout(queryTimer);
2164
+ }
2165
+ query += e.key.toLowerCase();
2166
+ this._searchForCountry(query);
2167
+ queryTimer = setTimeout(() => {
2168
+ query = "";
2169
+ }, 1e3);
2148
2170
  }
2149
2171
  };
2150
- let keyupTimer = null;
2151
- this._handleSearchChange = () => {
2152
- if (keyupTimer) {
2153
- clearTimeout(keyupTimer);
2172
+ document.addEventListener("keydown", this._handleKeydownOnDropdown);
2173
+ if (this.options.countrySearch) {
2174
+ const doFilter = () => {
2175
+ const inputQuery = this.searchInput.value.trim();
2176
+ if (inputQuery) {
2177
+ this._filterCountries(inputQuery);
2178
+ } else {
2179
+ this._filterCountries("", true);
2180
+ }
2181
+ };
2182
+ let keyupTimer = null;
2183
+ this._handleSearchChange = () => {
2184
+ if (keyupTimer) {
2185
+ clearTimeout(keyupTimer);
2186
+ }
2187
+ keyupTimer = setTimeout(() => {
2188
+ doFilter();
2189
+ keyupTimer = null;
2190
+ }, 100);
2191
+ };
2192
+ this.searchInput.addEventListener("input", this._handleSearchChange);
2193
+ this.searchInput.addEventListener("click", (e) => e.stopPropagation());
2194
+ }
2195
+ }
2196
+ //* Hidden search (countrySearch disabled): Find the first list item whose name starts with the query string.
2197
+ _searchForCountry(query) {
2198
+ for (let i = 0; i < this.countries.length; i++) {
2199
+ const c = this.countries[i];
2200
+ const startsWith = c.name.substr(0, query.length).toLowerCase() === query;
2201
+ if (startsWith) {
2202
+ const listItem = c.nodeById[this.id];
2203
+ this._highlightListItem(listItem, false);
2204
+ this._scrollTo(listItem);
2205
+ break;
2154
2206
  }
2155
- keyupTimer = setTimeout(() => {
2156
- doFilter();
2157
- keyupTimer = null;
2158
- }, 100);
2159
- };
2160
- this.searchInput.addEventListener("input", this._handleSearchChange);
2161
- this.searchInput.addEventListener("click", (e) => e.stopPropagation());
2207
+ }
2162
2208
  }
2209
+ //* Country search enabled: Filter the countries according to the search query.
2163
2210
  _filterCountries(query, isReset = false) {
2164
2211
  let noCountriesAddedYet = true;
2165
2212
  this.countryList.innerHTML = "";
@@ -2287,7 +2334,9 @@ var Iti = class {
2287
2334
  this.highlightedItem.setAttribute("aria-selected", "true");
2288
2335
  const activeDescendant = this.highlightedItem.getAttribute("id") || "";
2289
2336
  this.selectedCountry.setAttribute("aria-activedescendant", activeDescendant);
2290
- this.searchInput.setAttribute("aria-activedescendant", activeDescendant);
2337
+ if (this.options.countrySearch) {
2338
+ this.searchInput.setAttribute("aria-activedescendant", activeDescendant);
2339
+ }
2291
2340
  }
2292
2341
  if (shouldFocus) {
2293
2342
  this.highlightedItem.focus();
@@ -2444,10 +2493,14 @@ var Iti = class {
2444
2493
  if (this.highlightedItem) {
2445
2494
  this.highlightedItem.setAttribute("aria-selected", "false");
2446
2495
  }
2447
- this.searchInput.removeAttribute("aria-activedescendant");
2496
+ if (this.options.countrySearch) {
2497
+ this.searchInput.removeAttribute("aria-activedescendant");
2498
+ }
2448
2499
  this.dropdownArrow.classList.remove("iti__arrow--up");
2449
2500
  document.removeEventListener("keydown", this._handleKeydownOnDropdown);
2450
- this.searchInput.removeEventListener("input", this._handleSearchChange);
2501
+ if (this.options.countrySearch) {
2502
+ this.searchInput.removeEventListener("input", this._handleSearchChange);
2503
+ }
2451
2504
  document.documentElement.removeEventListener(
2452
2505
  "click",
2453
2506
  this._handleClickOffToClose
@@ -2602,7 +2655,8 @@ var Iti = class {
2602
2655
  //********************
2603
2656
  //* Remove plugin.
2604
2657
  destroy() {
2605
- if (this.options.allowDropdown) {
2658
+ const { allowDropdown, separateDialCode } = this.options;
2659
+ if (allowDropdown) {
2606
2660
  this._closeDropdown();
2607
2661
  this.selectedCountry.removeEventListener(
2608
2662
  "click",
@@ -2626,6 +2680,13 @@ var Iti = class {
2626
2680
  this.telInput.removeEventListener("keydown", this._handleKeydownEvent);
2627
2681
  }
2628
2682
  this.telInput.removeAttribute("data-intl-tel-input-id");
2683
+ if (separateDialCode) {
2684
+ if (this.isRTL) {
2685
+ this.telInput.style.paddingRight = this.originalPaddingRight;
2686
+ } else {
2687
+ this.telInput.style.paddingLeft = this.originalPaddingLeft;
2688
+ }
2689
+ }
2629
2690
  const wrapper = this.telInput.parentNode;
2630
2691
  wrapper?.parentNode?.insertBefore(this.telInput, wrapper);
2631
2692
  wrapper?.parentNode?.removeChild(wrapper);
@@ -2758,7 +2819,7 @@ var intlTelInput = Object.assign(
2758
2819
  //* A map from instance ID to instance object.
2759
2820
  instances: {},
2760
2821
  loadUtils,
2761
- version: "23.3.2"
2822
+ version: "23.4.1"
2762
2823
  }
2763
2824
  );
2764
2825
  var intl_tel_input_default = intlTelInput;
@@ -591,6 +591,7 @@ declare module "intl-tel-input" {
591
591
  autoPlaceholder: string;
592
592
  containerClass: string;
593
593
  countryOrder: string[];
594
+ countrySearch: boolean;
594
595
  customPlaceholder: ((selectedCountryPlaceholder: string, selectedCountryData: object) => string) | null;
595
596
  dropdownContainer: HTMLElement | null;
596
597
  excludeCountries: string[];
@@ -896,6 +897,8 @@ declare module "intl-tel-input" {
896
897
  private hiddenInputCountry;
897
898
  private maxCoreNumberLength;
898
899
  private defaultCountry;
900
+ private originalPaddingRight;
901
+ private originalPaddingLeft;
899
902
  private _handleHiddenInputSubmit;
900
903
  private _handleLabelClick;
901
904
  private _handleClickSelectedCountry;
@@ -934,6 +937,7 @@ declare module "intl-tel-input" {
934
937
  private _openDropdown;
935
938
  private _setDropdownPosition;
936
939
  private _bindDropdownListeners;
940
+ private _searchForCountry;
937
941
  private _filterCountries;
938
942
  private _updateSearchResultsText;
939
943
  private _handleUpDownKey;
@@ -1361,6 +1361,8 @@ var defaults = {
1361
1361
  containerClass: "",
1362
1362
  //* The order of the countries in the dropdown. Defaults to alphabetical.
1363
1363
  countryOrder: null,
1364
+ //* Add a country search input at the top of the dropdown.
1365
+ countrySearch: true,
1364
1366
  //* Modify the auto placeholder.
1365
1367
  customPlaceholder: null,
1366
1368
  //* Append menu to specified element.
@@ -1483,6 +1485,7 @@ var Iti = class {
1483
1485
  if (this.options.separateDialCode) {
1484
1486
  this.options.allowDropdown = true;
1485
1487
  this.options.nationalMode = false;
1488
+ this.options.countrySearch = true;
1486
1489
  }
1487
1490
  if (!this.options.showFlags && !this.options.separateDialCode) {
1488
1491
  this.options.nationalMode = false;
@@ -1492,6 +1495,13 @@ var Iti = class {
1492
1495
  }
1493
1496
  this.isAndroid = typeof navigator !== "undefined" ? /Android/i.test(navigator.userAgent) : false;
1494
1497
  this.isRTL = !!this.telInput.closest("[dir=rtl]");
1498
+ if (this.options.separateDialCode) {
1499
+ if (this.isRTL) {
1500
+ this.originalPaddingRight = this.telInput.style.paddingRight;
1501
+ } else {
1502
+ this.originalPaddingLeft = this.telInput.style.paddingLeft;
1503
+ }
1504
+ }
1495
1505
  this.options.i18n = { ...en_default, ...this.options.i18n };
1496
1506
  const autoCountryPromise = new Promise((resolve, reject) => {
1497
1507
  this.resolveAutoCountryPromise = resolve;
@@ -1635,6 +1645,7 @@ var Iti = class {
1635
1645
  dropdownContainer,
1636
1646
  fixDropdownWidth,
1637
1647
  useFullscreenPopup,
1648
+ countrySearch,
1638
1649
  i18n
1639
1650
  } = this.options;
1640
1651
  let parentClass = "iti";
@@ -1711,26 +1722,28 @@ var Iti = class {
1711
1722
  id: `iti-${this.id}__dropdown-content`,
1712
1723
  class: `iti__dropdown-content iti__hide ${extraClasses}`
1713
1724
  });
1714
- this.searchInput = createEl(
1715
- "input",
1716
- {
1717
- type: "text",
1718
- class: "iti__search-input",
1719
- placeholder: i18n.searchPlaceholder,
1720
- role: "combobox",
1721
- "aria-expanded": "true",
1722
- "aria-label": i18n.searchPlaceholder,
1723
- "aria-controls": `iti-${this.id}__country-listbox`,
1724
- "aria-autocomplete": "list",
1725
- "autocomplete": "off"
1726
- },
1727
- this.dropdownContent
1728
- );
1729
- this.searchResultsA11yText = createEl(
1730
- "span",
1731
- { class: "iti__a11y-text" },
1732
- this.dropdownContent
1733
- );
1725
+ if (countrySearch) {
1726
+ this.searchInput = createEl(
1727
+ "input",
1728
+ {
1729
+ type: "text",
1730
+ class: "iti__search-input",
1731
+ placeholder: i18n.searchPlaceholder,
1732
+ role: "combobox",
1733
+ "aria-expanded": "true",
1734
+ "aria-label": i18n.searchPlaceholder,
1735
+ "aria-controls": `iti-${this.id}__country-listbox`,
1736
+ "aria-autocomplete": "list",
1737
+ "autocomplete": "off"
1738
+ },
1739
+ this.dropdownContent
1740
+ );
1741
+ this.searchResultsA11yText = createEl(
1742
+ "span",
1743
+ { class: "iti__a11y-text" },
1744
+ this.dropdownContent
1745
+ );
1746
+ }
1734
1747
  this.countryList = createEl(
1735
1748
  "ul",
1736
1749
  {
@@ -1741,8 +1754,10 @@ var Iti = class {
1741
1754
  },
1742
1755
  this.dropdownContent
1743
1756
  );
1744
- this._appendListItems(this.countries, "iti__standard");
1745
- this._updateSearchResultsText();
1757
+ this._appendListItems();
1758
+ if (countrySearch) {
1759
+ this._updateSearchResultsText();
1760
+ }
1746
1761
  if (dropdownContainer) {
1747
1762
  let dropdownClasses = "iti iti--container";
1748
1763
  if (useFullscreenPopup) {
@@ -1777,15 +1792,16 @@ var Iti = class {
1777
1792
  }
1778
1793
  }
1779
1794
  }
1780
- //* For each of the passed countries: add a country <li> to the countryList <ul> container.
1781
- _appendListItems(countries, className) {
1782
- for (let i = 0; i < countries.length; i++) {
1783
- const c = countries[i];
1795
+ //* For each country: add a country list item <li> to the countryList <ul> container.
1796
+ _appendListItems() {
1797
+ for (let i = 0; i < this.countries.length; i++) {
1798
+ const c = this.countries[i];
1799
+ const extraClass = i === 0 ? "iti__highlight" : "";
1784
1800
  const listItem = createEl(
1785
1801
  "li",
1786
1802
  {
1787
1803
  id: `iti-${this.id}__item-${c.iso2}`,
1788
- class: `iti__country ${className}`,
1804
+ class: `iti__country ${extraClass}`,
1789
1805
  tabindex: "-1",
1790
1806
  role: "option",
1791
1807
  "data-dial-code": c.dialCode,
@@ -2026,24 +2042,26 @@ var Iti = class {
2026
2042
  }
2027
2043
  //* Open the dropdown.
2028
2044
  _openDropdown() {
2029
- const { fixDropdownWidth } = this.options;
2045
+ const { fixDropdownWidth, countrySearch } = this.options;
2030
2046
  if (fixDropdownWidth) {
2031
2047
  this.dropdownContent.style.width = `${this.telInput.offsetWidth}px`;
2032
2048
  }
2033
2049
  this.dropdownContent.classList.remove("iti__hide");
2034
2050
  this.selectedCountry.setAttribute("aria-expanded", "true");
2035
2051
  this._setDropdownPosition();
2036
- const firstCountryItem = this.countryList.firstElementChild;
2037
- if (firstCountryItem) {
2038
- this._highlightListItem(firstCountryItem, false);
2039
- this.countryList.scrollTop = 0;
2052
+ if (countrySearch) {
2053
+ const firstCountryItem = this.countryList.firstElementChild;
2054
+ if (firstCountryItem) {
2055
+ this._highlightListItem(firstCountryItem, false);
2056
+ this.countryList.scrollTop = 0;
2057
+ }
2058
+ this.searchInput.focus();
2040
2059
  }
2041
- this.searchInput.focus();
2042
2060
  this._bindDropdownListeners();
2043
2061
  this.dropdownArrow.classList.add("iti__arrow--up");
2044
2062
  this._trigger("open:countrydropdown");
2045
2063
  }
2046
- //* Decide if should position dropdown above or below input (depends on position within viewport, and scroll).
2064
+ //* Set the dropdown position
2047
2065
  _setDropdownPosition() {
2048
2066
  if (this.options.dropdownContainer) {
2049
2067
  this.options.dropdownContainer.appendChild(this.dropdown);
@@ -2089,6 +2107,8 @@ var Iti = class {
2089
2107
  "click",
2090
2108
  this._handleClickOffToClose
2091
2109
  );
2110
+ let query = "";
2111
+ let queryTimer = null;
2092
2112
  this._handleKeydownOnDropdown = (e) => {
2093
2113
  if (["ArrowUp", "ArrowDown", "Enter", "Escape"].includes(e.key)) {
2094
2114
  e.preventDefault();
@@ -2101,29 +2121,56 @@ var Iti = class {
2101
2121
  this._closeDropdown();
2102
2122
  }
2103
2123
  }
2104
- };
2105
- document.addEventListener("keydown", this._handleKeydownOnDropdown);
2106
- const doFilter = () => {
2107
- const inputQuery = this.searchInput.value.trim();
2108
- if (inputQuery) {
2109
- this._filterCountries(inputQuery);
2110
- } else {
2111
- this._filterCountries("", true);
2124
+ if (!this.options.countrySearch && /^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(e.key)) {
2125
+ e.stopPropagation();
2126
+ if (queryTimer) {
2127
+ clearTimeout(queryTimer);
2128
+ }
2129
+ query += e.key.toLowerCase();
2130
+ this._searchForCountry(query);
2131
+ queryTimer = setTimeout(() => {
2132
+ query = "";
2133
+ }, 1e3);
2112
2134
  }
2113
2135
  };
2114
- let keyupTimer = null;
2115
- this._handleSearchChange = () => {
2116
- if (keyupTimer) {
2117
- clearTimeout(keyupTimer);
2136
+ document.addEventListener("keydown", this._handleKeydownOnDropdown);
2137
+ if (this.options.countrySearch) {
2138
+ const doFilter = () => {
2139
+ const inputQuery = this.searchInput.value.trim();
2140
+ if (inputQuery) {
2141
+ this._filterCountries(inputQuery);
2142
+ } else {
2143
+ this._filterCountries("", true);
2144
+ }
2145
+ };
2146
+ let keyupTimer = null;
2147
+ this._handleSearchChange = () => {
2148
+ if (keyupTimer) {
2149
+ clearTimeout(keyupTimer);
2150
+ }
2151
+ keyupTimer = setTimeout(() => {
2152
+ doFilter();
2153
+ keyupTimer = null;
2154
+ }, 100);
2155
+ };
2156
+ this.searchInput.addEventListener("input", this._handleSearchChange);
2157
+ this.searchInput.addEventListener("click", (e) => e.stopPropagation());
2158
+ }
2159
+ }
2160
+ //* Hidden search (countrySearch disabled): Find the first list item whose name starts with the query string.
2161
+ _searchForCountry(query) {
2162
+ for (let i = 0; i < this.countries.length; i++) {
2163
+ const c = this.countries[i];
2164
+ const startsWith = c.name.substr(0, query.length).toLowerCase() === query;
2165
+ if (startsWith) {
2166
+ const listItem = c.nodeById[this.id];
2167
+ this._highlightListItem(listItem, false);
2168
+ this._scrollTo(listItem);
2169
+ break;
2118
2170
  }
2119
- keyupTimer = setTimeout(() => {
2120
- doFilter();
2121
- keyupTimer = null;
2122
- }, 100);
2123
- };
2124
- this.searchInput.addEventListener("input", this._handleSearchChange);
2125
- this.searchInput.addEventListener("click", (e) => e.stopPropagation());
2171
+ }
2126
2172
  }
2173
+ //* Country search enabled: Filter the countries according to the search query.
2127
2174
  _filterCountries(query, isReset = false) {
2128
2175
  let noCountriesAddedYet = true;
2129
2176
  this.countryList.innerHTML = "";
@@ -2251,7 +2298,9 @@ var Iti = class {
2251
2298
  this.highlightedItem.setAttribute("aria-selected", "true");
2252
2299
  const activeDescendant = this.highlightedItem.getAttribute("id") || "";
2253
2300
  this.selectedCountry.setAttribute("aria-activedescendant", activeDescendant);
2254
- this.searchInput.setAttribute("aria-activedescendant", activeDescendant);
2301
+ if (this.options.countrySearch) {
2302
+ this.searchInput.setAttribute("aria-activedescendant", activeDescendant);
2303
+ }
2255
2304
  }
2256
2305
  if (shouldFocus) {
2257
2306
  this.highlightedItem.focus();
@@ -2408,10 +2457,14 @@ var Iti = class {
2408
2457
  if (this.highlightedItem) {
2409
2458
  this.highlightedItem.setAttribute("aria-selected", "false");
2410
2459
  }
2411
- this.searchInput.removeAttribute("aria-activedescendant");
2460
+ if (this.options.countrySearch) {
2461
+ this.searchInput.removeAttribute("aria-activedescendant");
2462
+ }
2412
2463
  this.dropdownArrow.classList.remove("iti__arrow--up");
2413
2464
  document.removeEventListener("keydown", this._handleKeydownOnDropdown);
2414
- this.searchInput.removeEventListener("input", this._handleSearchChange);
2465
+ if (this.options.countrySearch) {
2466
+ this.searchInput.removeEventListener("input", this._handleSearchChange);
2467
+ }
2415
2468
  document.documentElement.removeEventListener(
2416
2469
  "click",
2417
2470
  this._handleClickOffToClose
@@ -2566,7 +2619,8 @@ var Iti = class {
2566
2619
  //********************
2567
2620
  //* Remove plugin.
2568
2621
  destroy() {
2569
- if (this.options.allowDropdown) {
2622
+ const { allowDropdown, separateDialCode } = this.options;
2623
+ if (allowDropdown) {
2570
2624
  this._closeDropdown();
2571
2625
  this.selectedCountry.removeEventListener(
2572
2626
  "click",
@@ -2590,6 +2644,13 @@ var Iti = class {
2590
2644
  this.telInput.removeEventListener("keydown", this._handleKeydownEvent);
2591
2645
  }
2592
2646
  this.telInput.removeAttribute("data-intl-tel-input-id");
2647
+ if (separateDialCode) {
2648
+ if (this.isRTL) {
2649
+ this.telInput.style.paddingRight = this.originalPaddingRight;
2650
+ } else {
2651
+ this.telInput.style.paddingLeft = this.originalPaddingLeft;
2652
+ }
2653
+ }
2593
2654
  const wrapper = this.telInput.parentNode;
2594
2655
  wrapper?.parentNode?.insertBefore(this.telInput, wrapper);
2595
2656
  wrapper?.parentNode?.removeChild(wrapper);
@@ -2722,7 +2783,7 @@ var intlTelInput = Object.assign(
2722
2783
  //* A map from instance ID to instance object.
2723
2784
  instances: {},
2724
2785
  loadUtils,
2725
- version: "23.3.2"
2786
+ version: "23.4.1"
2726
2787
  }
2727
2788
  );
2728
2789
  var intl_tel_input_default = intlTelInput;