intl-tel-input 27.2.0 → 27.3.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.
@@ -1966,6 +1966,8 @@ var defaults = {
1966
1966
  searchInputClass: "",
1967
1967
  //* Display the international dial code next to the selected flag.
1968
1968
  separateDialCode: false,
1969
+ //* When strictMode rejects a key (etc), play a short feedback animation
1970
+ strictRejectAnimation: false,
1969
1971
  //* Show flags - for both the selected country, and in the country dropdown
1970
1972
  showFlags: true,
1971
1973
  //* Only allow certain chars e.g. a plus followed by numeric digits, and cap at max valid length.
@@ -2041,6 +2043,7 @@ var validateOptions = (customOptions) => {
2041
2043
  case "showFlags":
2042
2044
  case "separateDialCode":
2043
2045
  case "strictMode":
2046
+ case "strictRejectAnimation":
2044
2047
  case "useFullscreenPopup":
2045
2048
  if (typeof value !== "boolean") {
2046
2049
  warnOption(key, "a boolean", value);
@@ -3529,9 +3532,7 @@ var Iti = class _Iti {
3529
3532
  this.#numerals = new Numerals(input.value);
3530
3533
  this.promise = this.#createInitPromise(this.#options);
3531
3534
  this.#countries = processAllCountries(this.#options);
3532
- const { dialCodes, dialCodeMaxLength, dialCodeToIso2Map } = processDialCodes(
3533
- this.#countries
3534
- );
3535
+ const { dialCodes, dialCodeMaxLength, dialCodeToIso2Map } = processDialCodes(this.#countries);
3535
3536
  this.#dialCodes = dialCodes;
3536
3537
  this.#dialCodeMaxLength = dialCodeMaxLength;
3537
3538
  this.#dialCodeToIso2Map = dialCodeToIso2Map;
@@ -3713,6 +3714,7 @@ var Iti = class _Iti {
3713
3714
  #handleAndroidStrictReject(inputValue, rejectedInput) {
3714
3715
  const newCaretPos = this.#removeJustTypedChar(inputValue);
3715
3716
  this.#ui.telInputEl.setSelectionRange(newCaretPos, newCaretPos);
3717
+ this.#playStrictRejectAnimation();
3716
3718
  this.#dispatchEvent(EVENTS.STRICT_REJECT, {
3717
3719
  source: "key",
3718
3720
  rejectedInput,
@@ -3772,7 +3774,13 @@ var Iti = class _Iti {
3772
3774
  //* On input event: (1) Update selected country, (2) Format-as-you-type.
3773
3775
  //* Note that this fires AFTER the input is updated.
3774
3776
  #handleInputEvent = (e) => {
3775
- const { strictMode, formatAsYouType, separateDialCode, allowDropdown, countrySearch } = this.#options;
3777
+ const {
3778
+ strictMode,
3779
+ formatAsYouType,
3780
+ separateDialCode,
3781
+ allowDropdown,
3782
+ countrySearch
3783
+ } = this.#options;
3776
3784
  const detail = e?.detail;
3777
3785
  if (detail?.["isCountryChange"]) {
3778
3786
  return;
@@ -3854,6 +3862,7 @@ var Iti = class _Iti {
3854
3862
  const newCountry = this.#resolveCountryChangeFromNumber(newFullNumber);
3855
3863
  const isChangingDialCode = newCountry !== null;
3856
3864
  if (!isAllowedChar || hasExceededMaxLength && !isChangingDialCode && !isInitialPlus) {
3865
+ this.#playStrictRejectAnimation();
3857
3866
  this.#dispatchEvent(EVENTS.STRICT_REJECT, {
3858
3867
  source: "key",
3859
3868
  rejectedInput: e.key,
@@ -3896,6 +3905,7 @@ var Iti = class _Iti {
3896
3905
  coreNumber = intlTelInput.utils.getCoreNumber(newValue, iso2);
3897
3906
  }
3898
3907
  if (!coreNumber) {
3908
+ this.#playStrictRejectAnimation();
3899
3909
  this.#dispatchEvent(EVENTS.STRICT_REJECT, {
3900
3910
  source: "paste",
3901
3911
  rejectedInput: pastedRaw,
@@ -3909,6 +3919,7 @@ var Iti = class _Iti {
3909
3919
  newValue = newValue.slice(0, newValue.length - trimLength);
3910
3920
  rejectReason = "max-length";
3911
3921
  } else {
3922
+ this.#playStrictRejectAnimation();
3912
3923
  this.#dispatchEvent(EVENTS.STRICT_REJECT, {
3913
3924
  source: "paste",
3914
3925
  rejectedInput: pastedRaw,
@@ -3923,6 +3934,9 @@ var Iti = class _Iti {
3923
3934
  input.setSelectionRange(caretPos, caretPos);
3924
3935
  input.dispatchEvent(new InputEvent("input", { bubbles: true }));
3925
3936
  if (rejectReason) {
3937
+ if (pasted.length > 0 && sanitised.length === 0) {
3938
+ this.#playStrictRejectAnimation();
3939
+ }
3926
3940
  this.#dispatchEvent(EVENTS.STRICT_REJECT, {
3927
3941
  source: "paste",
3928
3942
  rejectedInput: pastedRaw,
@@ -3935,6 +3949,21 @@ var Iti = class _Iti {
3935
3949
  const max = Number(this.#ui.telInputEl.getAttribute("maxlength"));
3936
3950
  return max && number.length > max ? number.substring(0, max) : number;
3937
3951
  }
3952
+ //* Play the strict-reject animation (shake, or background-colour flash under prefers-reduced-motion) on the wrapper.
3953
+ //* Called when strictMode rejects the whole input (keystroke, or whole paste).
3954
+ //* Uses the wrapper (not the input) so any separateDialCode / country button move together with the input.
3955
+ #playStrictRejectAnimation() {
3956
+ if (!this.#options.strictRejectAnimation) {
3957
+ return;
3958
+ }
3959
+ const wrapperEl = this.#ui.telInputEl.parentElement;
3960
+ if (!wrapperEl) {
3961
+ return;
3962
+ }
3963
+ wrapperEl.classList.remove("iti__strict-reject-animation");
3964
+ void wrapperEl.offsetWidth;
3965
+ wrapperEl.classList.add("iti__strict-reject-animation");
3966
+ }
3938
3967
  //* Trigger a custom event on the input (typed via ItiEventMap).
3939
3968
  #dispatchEvent(name, detailProps = {}) {
3940
3969
  const e = new CustomEvent(name, {
@@ -4571,7 +4600,7 @@ var intlTelInput = Object.assign(
4571
4600
  attachUtils,
4572
4601
  startedLoadingUtils: false,
4573
4602
  startedLoadingAutoCountry: false,
4574
- version: "27.2.0"
4603
+ version: "27.3.0"
4575
4604
  }
4576
4605
  );
4577
4606
  var intlTelInput_default = intlTelInput;