intl-tel-input 29.3.0 → 29.4.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.
@@ -1977,7 +1977,7 @@ var defaults = {
1977
1977
  customPlaceholder: null,
1978
1978
  //* Always show the dropdown
1979
1979
  dropdownAlwaysOpen: false,
1980
- //* Optional DOM element to append the dropdown to (used to escape ancestors with overflow:hidden, or to mount in a custom container). Only consulted in dropdown rendering; ignored when the country selector renders as a fullscreen popup.
1980
+ //* Optional DOM element to append the dropdown to (used to escape ancestors with overflow:hidden, or to mount in a custom container). Only consulted in dropdown rendering; ignored when the country selector renders as a fullscreen popup (see fullscreenParent).
1981
1981
  dropdownParent: null,
1982
1982
  //* Don't display these countries.
1983
1983
  excludeCountries: null,
@@ -1985,6 +1985,8 @@ var defaults = {
1985
1985
  matchDropdownWidth: true,
1986
1986
  //* Format the number as the user types
1987
1987
  formatAsYouType: true,
1988
+ //* Optional DOM element to append the fullscreen popup to, instead of document.body (e.g. a modal <dialog>, where a body-mounted popup would be unreachable). Only consulted in fullscreen rendering (see dropdownParent for the dropdown). Null means document.body, which is resolved on open rather than here, as document may not exist yet (e.g. SSR).
1989
+ fullscreenParent: null,
1988
1990
  //* Inject hidden inputs with the names returned from this function, and on submit, populate them with the full number and selected country iso2.
1989
1991
  hiddenInputs: null,
1990
1992
  //* Translations for the core library UI strings e.g. search input placeholder, country names.
@@ -2168,8 +2170,9 @@ var validateOptions = (customOptions) => {
2168
2170
  validatedOptions[key] = value;
2169
2171
  break;
2170
2172
  case "dropdownParent":
2173
+ case "fullscreenParent":
2171
2174
  if (value !== null && !isElLike(value)) {
2172
- warnOption("dropdownParent", "an HTMLElement or null", value);
2175
+ warnOption(key, "an HTMLElement or null", value);
2173
2176
  break;
2174
2177
  }
2175
2178
  validatedOptions[key] = value;
@@ -2733,6 +2736,9 @@ var UI = class {
2733
2736
  },
2734
2737
  this.#countrySelectorEl
2735
2738
  );
2739
+ if (!countrySearch) {
2740
+ this.#countryListEl.setAttribute("tabindex", "0");
2741
+ }
2736
2742
  this.#appendListItems();
2737
2743
  if (countrySearch) {
2738
2744
  this.#updateSearchResultsA11yText();
@@ -2753,11 +2759,12 @@ var UI = class {
2753
2759
  this.#countryContainerEl.appendChild(this.#countrySelectorEl);
2754
2760
  }
2755
2761
  }
2756
- //* Resolve the DOM element to attach the country selector to. Fullscreen always uses document.body; dropdown uses the consumer-supplied dropdownParent (if any); otherwise the country selector renders inline within the input wrapper (no detached element).
2762
+ //* Resolve the DOM element to attach the country selector to. Fullscreen is always detached: it uses the consumer-supplied fullscreenParent, falling back to document.body; dropdown uses the consumer-supplied dropdownParent (if any); otherwise the country selector renders inline within the input wrapper (no detached element).
2763
+ //* NOTE: these are deliberately two separate options. For the dropdown, setting a parent switches it from inline to detached rendering (pos:fixed, positioned against the input), whereas the fullscreen popup is detached regardless, so its parent only relocates it. Sharing one option would force a detached dropdown on anyone who only needs to move the fullscreen popup e.g. into a modal <dialog> (issue #2199).
2757
2764
  #getDetachedParent() {
2758
- const { countrySelectorMode, dropdownParent } = this.#options;
2765
+ const { countrySelectorMode, dropdownParent, fullscreenParent } = this.#options;
2759
2766
  if (countrySelectorMode === COUNTRY_SELECTOR_MODE.FULLSCREEN) {
2760
- return document.body;
2767
+ return fullscreenParent ?? document.body;
2761
2768
  }
2762
2769
  if (countrySelectorMode === COUNTRY_SELECTOR_MODE.DROPDOWN) {
2763
2770
  return dropdownParent;
@@ -2883,7 +2890,6 @@ var UI = class {
2883
2890
  const listItem = createEl("li", {
2884
2891
  id: `iti-${this.#id}__item-${c.iso2}`,
2885
2892
  class: liClass,
2886
- tabindex: "-1",
2887
2893
  role: "option",
2888
2894
  [ARIA.SELECTED]: "false"
2889
2895
  });
@@ -3075,18 +3081,20 @@ var UI = class {
3075
3081
  container.scrollTop = offsetTop - containerRect.height + elementRect.height;
3076
3082
  }
3077
3083
  }
3084
+ //* The element that holds focus while the country selector is open: the search input, or (when countrySearch is disabled) the country list itself.
3085
+ #getOpenFocusEl() {
3086
+ return this.#options.countrySearch ? this.#searchInputEl : this.#countryListEl;
3087
+ }
3078
3088
  //* Remove highlighting from the previous list item and highlight the new one.
3079
3089
  #highlightListItem(listItem, doScroll = true) {
3080
3090
  this.#highlightedListItemEl?.classList.remove(CLASSES.HIGHLIGHT);
3081
3091
  if (listItem) {
3082
3092
  listItem.classList.add(CLASSES.HIGHLIGHT);
3083
- if (this.#options.countrySearch) {
3084
- const activeDescendant = listItem.getAttribute("id") || "";
3085
- this.#searchInputEl.setAttribute(
3086
- ARIA.ACTIVE_DESCENDANT,
3087
- activeDescendant
3088
- );
3089
- }
3093
+ const activeDescendant = listItem.getAttribute("id") || "";
3094
+ this.#getOpenFocusEl().setAttribute(
3095
+ ARIA.ACTIVE_DESCENDANT,
3096
+ activeDescendant
3097
+ );
3090
3098
  if (doScroll) {
3091
3099
  this.#scrollCountryListToItem(listItem);
3092
3100
  }
@@ -3165,7 +3173,7 @@ var UI = class {
3165
3173
  //* Open the country selector: create a fresh AbortController, do the DOM work, and wire up all
3166
3174
  //* open-state listeners (which invoke the caller's onSelect / onClose callbacks).
3167
3175
  openCountrySelector(onSelect, onClose) {
3168
- const { countrySearch, dropdownAlwaysOpen } = this.#options;
3176
+ const { dropdownAlwaysOpen } = this.#options;
3169
3177
  this.#countrySelectorAbortController = new AbortController();
3170
3178
  if (this.#options.countrySelectorMode !== COUNTRY_SELECTOR_MODE.FULLSCREEN) {
3171
3179
  this.#ensureInlineDropdownSizeMeasured();
@@ -3188,10 +3196,11 @@ var UI = class {
3188
3196
  if (itemToHighlight) {
3189
3197
  this.#highlightListItem(itemToHighlight);
3190
3198
  }
3191
- if (countrySearch && !dropdownAlwaysOpen) {
3192
- this.#searchInputEl.focus();
3199
+ if (!dropdownAlwaysOpen) {
3200
+ this.#getOpenFocusEl().focus();
3193
3201
  }
3194
3202
  if (this.#options.countrySelectorMode === COUNTRY_SELECTOR_MODE.FULLSCREEN && this.#detachedCountrySelectorEl && window.visualViewport) {
3203
+ this.#adjustFullscreenPopupToViewport();
3195
3204
  window.visualViewport.addEventListener(
3196
3205
  "resize",
3197
3206
  () => {
@@ -3308,6 +3317,20 @@ var UI = class {
3308
3317
  };
3309
3318
  this.#selectedCountryEl?.addEventListener("keydown", handleKeydown, { signal });
3310
3319
  this.#countrySelectorEl?.addEventListener("keydown", handleKeydown, { signal });
3320
+ if (this.#detachedCountrySelectorEl) {
3321
+ this.#countrySelectorEl?.addEventListener(
3322
+ "keydown",
3323
+ (e) => {
3324
+ if (e.key === KEYS.TAB) {
3325
+ e.preventDefault();
3326
+ onEscape();
3327
+ const focusEl = e.shiftKey ? this.#selectedCountryEl : this.telInputEl;
3328
+ focusEl.focus();
3329
+ }
3330
+ },
3331
+ { signal }
3332
+ );
3333
+ }
3311
3334
  }
3312
3335
  //* Wire up country search input listener: typing filters the list, the clear button resets it.
3313
3336
  #bindSearchInputListener(signal) {
@@ -3405,8 +3428,8 @@ var UI = class {
3405
3428
  this.#countrySelectorAbortController = null;
3406
3429
  this.#countrySelectorEl.classList.add(CLASSES.HIDE);
3407
3430
  this.#selectedCountryEl.setAttribute(ARIA.EXPANDED, "false");
3431
+ this.#getOpenFocusEl().removeAttribute(ARIA.ACTIVE_DESCENDANT);
3408
3432
  if (countrySearch) {
3409
- this.#searchInputEl.removeAttribute(ARIA.ACTIVE_DESCENDANT);
3410
3433
  this.#searchInputEl.value = "";
3411
3434
  this.#applySearchFilter();
3412
3435
  if (this.#highlightedListItemEl) {
@@ -3419,6 +3442,7 @@ var UI = class {
3419
3442
  this.#detachedCountrySelectorEl.remove();
3420
3443
  this.#detachedCountrySelectorEl.style.top = "";
3421
3444
  this.#detachedCountrySelectorEl.style.bottom = "";
3445
+ this.#detachedCountrySelectorEl.style.height = "";
3422
3446
  this.#detachedCountrySelectorEl.style.paddingLeft = "";
3423
3447
  this.#detachedCountrySelectorEl.style.paddingRight = "";
3424
3448
  } else {
@@ -3484,8 +3508,7 @@ var UI = class {
3484
3508
  if (!vv || !this.#detachedCountrySelectorEl) {
3485
3509
  return;
3486
3510
  }
3487
- const virtualKeyboardHeight = window.innerHeight - vv.height;
3488
- this.#detachedCountrySelectorEl.style.bottom = `${virtualKeyboardHeight}px`;
3511
+ this.#detachedCountrySelectorEl.style.height = `${vv.height}px`;
3489
3512
  }
3490
3513
  // UI: Whether the country selector is currently open (visible).
3491
3514
  isCountrySelectorOpen() {
@@ -4955,7 +4978,7 @@ var intlTelInput = Object.assign(
4955
4978
  attachUtils,
4956
4979
  startedLoadingUtils: false,
4957
4980
  startedLoadingAutoCountry: false,
4958
- version: "29.3.0",
4981
+ version: "29.4.0",
4959
4982
  NUMBER_FORMAT,
4960
4983
  NUMBER_TYPE,
4961
4984
  VALIDATION_ERROR,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intl-tel-input",
3
- "version": "29.3.0",
3
+ "version": "29.4.0",
4
4
  "description": "A JavaScript library for entering, formatting, and validating international telephone numbers",
5
5
  "type": "module",
6
6
  "license": "MIT",