intl-tel-input 27.1.2 → 27.2.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.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  See the Github Releases page for changelog: https://github.com/jackocnr/intl-tel-input/releases
2
2
 
3
- Or to view a specific version, e.g. v27.1.2, update the URL accordingly, e.g. https://github.com/jackocnr/intl-tel-input/releases/tag/v27.1.2
3
+ Or to view a specific version, e.g. v27.2.0, update the URL accordingly, e.g. https://github.com/jackocnr/intl-tel-input/releases/tag/v27.2.0
4
4
 
5
5
  ## Breaking changes
6
6
 
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  A JavaScript plugin for entering, formatting and validating international telephone numbers. Includes React, Vue, Angular and Svelte components, plus TypeScript definitions.
5
5
 
6
- [Explore docs »](https://intl-tel-input.com/docs/choose-integration)
6
+ [Explore docs »](https://intl-tel-input.com/docs/integrations)
7
7
 
8
8
  <picture>
9
9
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/iti-github-dark.png">
@@ -20,7 +20,7 @@ Use [Twilio's API to build phone verification, SMS 2FA, appointment reminders, m
20
20
  We provide React, Vue, Angular and Svelte (beta) components alongside the regular JavaScript plugin. This readme is for the JavaScript plugin. View the [React Component](https://intl-tel-input.com/docs/react-component), the [Vue Component](https://intl-tel-input.com/docs/vue-component) the [Angular Component](https://intl-tel-input.com/docs/angular-component), or the [Svelte component](https://intl-tel-input.com/docs/svelte-component).
21
21
 
22
22
  ## Docs and Examples
23
- We have a newly updated website, where you can find [a full set of docs](https://intl-tel-input.com/docs/getting-started.html), a [live playground](https://intl-tel-input.com/playground/) where you can try out all of the options, as well as plenty of [examples](https://intl-tel-input.com/examples/validation-practical.html) of different setups.
23
+ We have a newly updated website, where you can find [a full set of docs](https://intl-tel-input.com/docs/integrations), a [live playground](https://intl-tel-input.com/playground/) where you can try out all of the options, as well as plenty of [examples](https://intl-tel-input.com/examples/validation-practical.html) of different setups.
24
24
 
25
25
  ## Features
26
26
  * Automatically select the user's current country using an IP lookup
package/angular/README.md CHANGED
@@ -3,3 +3,11 @@
3
3
  An Angular component for the [intl-tel-input](https://github.com/jackocnr/intl-tel-input) JavaScript plugin. View the [source code](https://github.com/jackocnr/intl-tel-input/blob/master/angular/src/IntlTelInput.ts).
4
4
 
5
5
  [Explore docs »](https://intl-tel-input.com/docs/angular-component)
6
+
7
+ ## Running the demos locally
8
+
9
+ 1. Initialise the submodules: `git submodule update --init --recursive`
10
+ 2. Install dependencies: `npm install`
11
+ 3. Build: `npm run build`
12
+
13
+ You can then open `angular/demo/validation/index.html` in your browser to try the validation demo. View the full list of [available demos](https://github.com/jackocnr/intl-tel-input/tree/master/angular/demo).
@@ -4,6 +4,11 @@ import { OnDestroy, ElementRef, EventEmitter, AfterViewInit, OnChanges, SimpleCh
4
4
  import { ControlValueAccessor, Validator, AbstractControl, ValidationErrors } from "@angular/forms";
5
5
  import * as i0 from "@angular/core";
6
6
  export { intlTelInput };
7
+ export type StrictRejectDetail = {
8
+ source: "key" | "paste";
9
+ rejectedInput: string;
10
+ reason: "invalid" | "max-length";
11
+ };
7
12
  declare class IntlTelInput implements AfterViewInit, OnDestroy, OnChanges, ControlValueAccessor, Validator {
8
13
  inputRef: ElementRef<HTMLInputElement>;
9
14
  /** initialValue is only used during initialization — changes after init are ignored. */
@@ -45,6 +50,9 @@ declare class IntlTelInput implements AfterViewInit, OnDestroy, OnChanges, Contr
45
50
  countryChange: EventEmitter<string>;
46
51
  validityChange: EventEmitter<boolean>;
47
52
  errorCodeChange: EventEmitter<number | null>;
53
+ openCountryDropdown: EventEmitter<void>;
54
+ closeCountryDropdown: EventEmitter<void>;
55
+ strictReject: EventEmitter<StrictRejectDetail>;
48
56
  blur: EventEmitter<FocusEvent>;
49
57
  focus: EventEmitter<FocusEvent>;
50
58
  keydown: EventEmitter<KeyboardEvent>;
@@ -58,9 +66,13 @@ declare class IntlTelInput implements AfterViewInit, OnDestroy, OnChanges, Contr
58
66
  private lastEmittedValidity?;
59
67
  private lastEmittedErrorCode?;
60
68
  private pendingWriteValue?;
69
+ private pendingUpdate;
61
70
  private onChange;
62
71
  private onTouched;
63
72
  private onValidatorChange;
73
+ private handleOpenDropdown;
74
+ private handleCloseDropdown;
75
+ private handleStrictReject;
64
76
  ngAfterViewInit(): void;
65
77
  private buildInitOptions;
66
78
  ngOnChanges(changes: SimpleChanges): void;
@@ -91,6 +103,6 @@ declare class IntlTelInput implements AfterViewInit, OnDestroy, OnChanges, Contr
91
103
  validate(_control: AbstractControl): ValidationErrors | null;
92
104
  registerOnValidatorChange(fn: () => void): void;
93
105
  static ɵfac: i0.ɵɵFactoryDeclaration<IntlTelInput, never>;
94
- static ɵcmp: i0.ɵɵComponentDeclaration<IntlTelInput, "intl-tel-input", never, { "initialValue": { "alias": "initialValue"; "required": false; }; "usePreciseValidation": { "alias": "usePreciseValidation"; "required": false; }; "inputAttributes": { "alias": "inputAttributes"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; "readonly": { "alias": "readonly"; "required": false; }; "allowDropdown": { "alias": "allowDropdown"; "required": false; }; "allowedNumberTypes": { "alias": "allowedNumberTypes"; "required": false; }; "allowNumberExtensions": { "alias": "allowNumberExtensions"; "required": false; }; "allowPhonewords": { "alias": "allowPhonewords"; "required": false; }; "autoPlaceholder": { "alias": "autoPlaceholder"; "required": false; }; "containerClass": { "alias": "containerClass"; "required": false; }; "countryNameLocale": { "alias": "countryNameLocale"; "required": false; }; "countryOrder": { "alias": "countryOrder"; "required": false; }; "countrySearch": { "alias": "countrySearch"; "required": false; }; "customPlaceholder": { "alias": "customPlaceholder"; "required": false; }; "dropdownAlwaysOpen": { "alias": "dropdownAlwaysOpen"; "required": false; }; "dropdownContainer": { "alias": "dropdownContainer"; "required": false; }; "excludeCountries": { "alias": "excludeCountries"; "required": false; }; "fixDropdownWidth": { "alias": "fixDropdownWidth"; "required": false; }; "formatAsYouType": { "alias": "formatAsYouType"; "required": false; }; "formatOnDisplay": { "alias": "formatOnDisplay"; "required": false; }; "geoIpLookup": { "alias": "geoIpLookup"; "required": false; }; "hiddenInput": { "alias": "hiddenInput"; "required": false; }; "i18n": { "alias": "i18n"; "required": false; }; "initialCountry": { "alias": "initialCountry"; "required": false; }; "loadUtils": { "alias": "loadUtils"; "required": false; }; "nationalMode": { "alias": "nationalMode"; "required": false; }; "onlyCountries": { "alias": "onlyCountries"; "required": false; }; "placeholderNumberType": { "alias": "placeholderNumberType"; "required": false; }; "searchInputClass": { "alias": "searchInputClass"; "required": false; }; "separateDialCode": { "alias": "separateDialCode"; "required": false; }; "showFlags": { "alias": "showFlags"; "required": false; }; "strictMode": { "alias": "strictMode"; "required": false; }; "useFullscreenPopup": { "alias": "useFullscreenPopup"; "required": false; }; }, { "numberChange": "numberChange"; "countryChange": "countryChange"; "validityChange": "validityChange"; "errorCodeChange": "errorCodeChange"; "blur": "blur"; "focus": "focus"; "keydown": "keydown"; "keyup": "keyup"; "paste": "paste"; "click": "click"; }, never, never, true, never>;
106
+ static ɵcmp: i0.ɵɵComponentDeclaration<IntlTelInput, "intl-tel-input", never, { "initialValue": { "alias": "initialValue"; "required": false; }; "usePreciseValidation": { "alias": "usePreciseValidation"; "required": false; }; "inputAttributes": { "alias": "inputAttributes"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; "readonly": { "alias": "readonly"; "required": false; }; "allowDropdown": { "alias": "allowDropdown"; "required": false; }; "allowedNumberTypes": { "alias": "allowedNumberTypes"; "required": false; }; "allowNumberExtensions": { "alias": "allowNumberExtensions"; "required": false; }; "allowPhonewords": { "alias": "allowPhonewords"; "required": false; }; "autoPlaceholder": { "alias": "autoPlaceholder"; "required": false; }; "containerClass": { "alias": "containerClass"; "required": false; }; "countryNameLocale": { "alias": "countryNameLocale"; "required": false; }; "countryOrder": { "alias": "countryOrder"; "required": false; }; "countrySearch": { "alias": "countrySearch"; "required": false; }; "customPlaceholder": { "alias": "customPlaceholder"; "required": false; }; "dropdownAlwaysOpen": { "alias": "dropdownAlwaysOpen"; "required": false; }; "dropdownContainer": { "alias": "dropdownContainer"; "required": false; }; "excludeCountries": { "alias": "excludeCountries"; "required": false; }; "fixDropdownWidth": { "alias": "fixDropdownWidth"; "required": false; }; "formatAsYouType": { "alias": "formatAsYouType"; "required": false; }; "formatOnDisplay": { "alias": "formatOnDisplay"; "required": false; }; "geoIpLookup": { "alias": "geoIpLookup"; "required": false; }; "hiddenInput": { "alias": "hiddenInput"; "required": false; }; "i18n": { "alias": "i18n"; "required": false; }; "initialCountry": { "alias": "initialCountry"; "required": false; }; "loadUtils": { "alias": "loadUtils"; "required": false; }; "nationalMode": { "alias": "nationalMode"; "required": false; }; "onlyCountries": { "alias": "onlyCountries"; "required": false; }; "placeholderNumberType": { "alias": "placeholderNumberType"; "required": false; }; "searchInputClass": { "alias": "searchInputClass"; "required": false; }; "separateDialCode": { "alias": "separateDialCode"; "required": false; }; "showFlags": { "alias": "showFlags"; "required": false; }; "strictMode": { "alias": "strictMode"; "required": false; }; "useFullscreenPopup": { "alias": "useFullscreenPopup"; "required": false; }; }, { "numberChange": "numberChange"; "countryChange": "countryChange"; "validityChange": "validityChange"; "errorCodeChange": "errorCodeChange"; "openCountryDropdown": "openCountryDropdown"; "closeCountryDropdown": "closeCountryDropdown"; "strictReject": "strictReject"; "blur": "blur"; "focus": "focus"; "keydown": "keydown"; "keyup": "keyup"; "paste": "paste"; "click": "click"; }, never, never, true, never>;
95
107
  }
96
108
  export default IntlTelInput;
@@ -2975,7 +2975,7 @@ var UI = class _UI {
2975
2975
  this.#selectedCountryEl.focus();
2976
2976
  }
2977
2977
  }
2978
- if (!this.#options.countrySearch && REGEX.HIDDEN_SEARCH_CHAR.test(e.key)) {
2978
+ if (!this.#options.countrySearch && e.target !== this.telInputEl && REGEX.HIDDEN_SEARCH_CHAR.test(e.key)) {
2979
2979
  e.stopPropagation();
2980
2980
  if (queryTimer) {
2981
2981
  clearTimeout(queryTimer);
@@ -3483,6 +3483,8 @@ var Iti = class _Iti {
3483
3483
  #isActive = true;
3484
3484
  #abortController;
3485
3485
  #numerals;
3486
+ //* Tracks whether the user has typed/pasted their own formatting chars, so AYT-formatting should back off.
3487
+ #userOverrideFormatting = false;
3486
3488
  #autoCountryDeferred;
3487
3489
  #utilsDeferred;
3488
3490
  constructor(input, customOptions = {}) {
@@ -3672,176 +3674,211 @@ var Iti = class _Iti {
3672
3674
  this.#bindKeydownListener();
3673
3675
  this.#bindPasteListener();
3674
3676
  }
3675
- #bindInputListener() {
3676
- const {
3677
- strictMode,
3678
- formatAsYouType,
3679
- separateDialCode,
3680
- allowDropdown,
3681
- countrySearch
3682
- } = this.#options;
3683
- let userOverrideFormatting = false;
3684
- if (REGEX.ALPHA_UNICODE.test(this.#getTelInputValue())) {
3685
- userOverrideFormatting = true;
3677
+ //* Android workaround for handling plus when separateDialCode enabled (as impossible to handle with keydown/keyup, for which e.key always returns "Unidentified", see https://stackoverflow.com/q/59584061/217866)
3678
+ #handleAndroidPlusKey(inputValue) {
3679
+ this.#removeJustTypedChar(inputValue);
3680
+ this.#openDropdownWithPlus();
3681
+ }
3682
+ //* Android strictMode workaround: the keydown-based filter can't block these because e.key is "Unidentified" on Android virtual keyboards, so strip them here on input.
3683
+ #handleAndroidStrictReject(inputValue, rejectedInput) {
3684
+ const newCaretPos = this.#removeJustTypedChar(inputValue);
3685
+ this.#ui.telInputEl.setSelectionRange(newCaretPos, newCaretPos);
3686
+ this.#dispatchEvent(EVENTS.STRICT_REJECT, {
3687
+ source: "key",
3688
+ rejectedInput,
3689
+ reason: "invalid"
3690
+ });
3691
+ }
3692
+ //* Format the input value using libphonenumber's AYT formatter, preserving caret position (called after an input event).
3693
+ #formatAsYouType(inputValue, isDeleteForwards) {
3694
+ const currentCaretPos = this.#ui.telInputEl.selectionStart || 0;
3695
+ const valueBeforeCaret = inputValue.substring(0, currentCaretPos);
3696
+ const relevantCharsBeforeCaret = valueBeforeCaret.replace(
3697
+ REGEX.NON_PLUS_NUMERIC_GLOBAL,
3698
+ ""
3699
+ ).length;
3700
+ const fullNumber = this.#getFullNumber();
3701
+ const formattedValue = formatNumberAsYouType(
3702
+ fullNumber,
3703
+ inputValue,
3704
+ intlTelInput.utils,
3705
+ this.#selectedCountry,
3706
+ this.#options.separateDialCode
3707
+ );
3708
+ const newCaretPos = computeNewCaretPosition(
3709
+ relevantCharsBeforeCaret,
3710
+ formattedValue,
3711
+ currentCaretPos,
3712
+ isDeleteForwards
3713
+ );
3714
+ this.#setTelInputValue(formattedValue);
3715
+ this.#ui.telInputEl.setSelectionRange(newCaretPos, newCaretPos);
3716
+ }
3717
+ //* If separateDialCode AND typed dial code (e.g. from paste or autofill, or from typing a dial code when countrySearch disabled), then remove the typed dial code.
3718
+ //* Only strip when a full dial code is actually present — otherwise a lone typed "+" (or partial prefix) would get erased.
3719
+ #stripTypedDialCode(inputValue) {
3720
+ if (inputValue.startsWith("+") && this.#selectedCountry && this.#getDialCode(inputValue)) {
3721
+ const cleanNumber = stripSeparateDialCode(
3722
+ inputValue,
3723
+ true,
3724
+ true,
3725
+ this.#selectedCountry
3726
+ );
3727
+ this.#setTelInputValue(cleanNumber);
3686
3728
  }
3687
- const handleInputEvent = (e) => {
3688
- if (e?.detail && e.detail["isCountryChange"]) {
3689
- return;
3690
- }
3691
- const inputValue = this.#getTelInputValue();
3692
- if (this.#isAndroid && e?.data === "+" && separateDialCode && allowDropdown && countrySearch) {
3693
- this.#removeJustTypedChar(inputValue);
3694
- this.#openDropdownWithPlus();
3695
- return;
3696
- }
3697
- if (this.#isAndroid && strictMode && (e?.data === " " || e?.data === "-" || e?.data === ".")) {
3698
- const newCaretPos = this.#removeJustTypedChar(inputValue);
3699
- this.#ui.telInputEl.setSelectionRange(newCaretPos, newCaretPos);
3700
- this.#dispatchEvent(EVENTS.STRICT_REJECT, {
3701
- source: "key",
3702
- rejectedInput: e.data,
3703
- reason: "invalid"
3704
- });
3705
- return;
3706
- }
3707
- if (this.#updateCountryFromNumber(inputValue)) {
3708
- this.#dispatchCountryChangeEvent();
3709
- }
3710
- const isFormattingChar = e?.data && REGEX.NON_PLUS_NUMERIC.test(e.data);
3711
- const isPaste = e?.inputType === INPUT_TYPES.PASTE && inputValue;
3712
- if (isFormattingChar || isPaste && !strictMode) {
3713
- userOverrideFormatting = true;
3714
- } else if (!REGEX.NON_PLUS_NUMERIC.test(inputValue)) {
3715
- userOverrideFormatting = false;
3716
- }
3717
- const isSetNumber = e?.detail && e.detail["isSetNumber"];
3718
- const isAscii = this.#numerals.isAscii();
3719
- if (formatAsYouType && !userOverrideFormatting && !isSetNumber && isAscii) {
3720
- const currentCaretPos = this.#ui.telInputEl.selectionStart || 0;
3721
- const valueBeforeCaret = inputValue.substring(0, currentCaretPos);
3722
- const relevantCharsBeforeCaret = valueBeforeCaret.replace(
3723
- REGEX.NON_PLUS_NUMERIC_GLOBAL,
3724
- ""
3725
- ).length;
3726
- const isDeleteForwards = e?.inputType === INPUT_TYPES.DELETE_FORWARD;
3727
- const fullNumber = this.#getFullNumber();
3728
- const formattedValue = formatNumberAsYouType(
3729
- fullNumber,
3730
- inputValue,
3731
- intlTelInput.utils,
3732
- this.#selectedCountry,
3733
- separateDialCode
3734
- );
3735
- const newCaretPos = computeNewCaretPosition(
3736
- relevantCharsBeforeCaret,
3737
- formattedValue,
3738
- currentCaretPos,
3739
- isDeleteForwards
3740
- );
3741
- this.#setTelInputValue(formattedValue);
3742
- this.#ui.telInputEl.setSelectionRange(newCaretPos, newCaretPos);
3743
- }
3744
- if (separateDialCode && inputValue.startsWith("+") && this.#selectedCountry?.dialCode) {
3745
- const cleanNumber = stripSeparateDialCode(
3746
- inputValue,
3747
- true,
3748
- separateDialCode,
3749
- this.#selectedCountry
3750
- );
3751
- this.#setTelInputValue(cleanNumber);
3752
- }
3753
- };
3729
+ }
3730
+ #bindInputListener() {
3731
+ this.#userOverrideFormatting = REGEX.ALPHA_UNICODE.test(
3732
+ this.#getTelInputValue()
3733
+ );
3754
3734
  this.#ui.telInputEl.addEventListener(
3755
3735
  "input",
3756
- handleInputEvent,
3736
+ this.#handleInputEvent,
3757
3737
  {
3758
3738
  signal: this.#abortController.signal
3759
3739
  }
3760
3740
  );
3761
3741
  }
3742
+ //* On input event: (1) Update selected country, (2) Format-as-you-type.
3743
+ //* Note that this fires AFTER the input is updated.
3744
+ #handleInputEvent = (e) => {
3745
+ const { strictMode, formatAsYouType, separateDialCode, allowDropdown, countrySearch } = this.#options;
3746
+ const detail = e?.detail;
3747
+ if (detail?.["isCountryChange"]) {
3748
+ return;
3749
+ }
3750
+ const inputValue = this.#getTelInputValue();
3751
+ if (this.#isAndroid && e?.data === "+" && separateDialCode && allowDropdown && countrySearch) {
3752
+ this.#handleAndroidPlusKey(inputValue);
3753
+ return;
3754
+ }
3755
+ if (this.#isAndroid && strictMode && (e?.data === " " || e?.data === "-" || e?.data === ".")) {
3756
+ this.#handleAndroidStrictReject(inputValue, e.data);
3757
+ return;
3758
+ }
3759
+ if (this.#updateCountryFromNumber(inputValue)) {
3760
+ this.#dispatchCountryChangeEvent();
3761
+ }
3762
+ const isFormattingChar = e?.data && REGEX.NON_PLUS_NUMERIC.test(e.data);
3763
+ const isPaste = e?.inputType === INPUT_TYPES.PASTE && inputValue;
3764
+ if (isFormattingChar || isPaste && !strictMode) {
3765
+ this.#userOverrideFormatting = true;
3766
+ } else if (!REGEX.NON_PLUS_NUMERIC.test(inputValue)) {
3767
+ this.#userOverrideFormatting = false;
3768
+ }
3769
+ if (formatAsYouType && !this.#userOverrideFormatting && !detail?.["isSetNumber"] && this.#numerals.isAscii()) {
3770
+ this.#formatAsYouType(
3771
+ inputValue,
3772
+ e?.inputType === INPUT_TYPES.DELETE_FORWARD
3773
+ );
3774
+ }
3775
+ if (separateDialCode) {
3776
+ this.#stripTypedDialCode(inputValue);
3777
+ }
3778
+ };
3762
3779
  #bindKeydownListener() {
3763
- const { strictMode, separateDialCode, allowDropdown, countrySearch } = this.#options;
3780
+ const { strictMode, separateDialCode } = this.#options;
3764
3781
  if (!strictMode && !separateDialCode) {
3765
3782
  return;
3766
3783
  }
3767
- const handleKeydownEvent = (e) => {
3768
- if (!e.key || e.key.length !== 1 || e.altKey || e.ctrlKey || e.metaKey) {
3769
- return;
3770
- }
3771
- if (separateDialCode && allowDropdown && countrySearch && e.key === "+") {
3772
- e.preventDefault();
3773
- this.#openDropdownWithPlus();
3774
- return;
3775
- }
3776
- if (!strictMode) {
3777
- return;
3778
- }
3779
- const inputValue = this.#getTelInputValue();
3780
- const alreadyHasPlus = inputValue.startsWith("+");
3781
- const isInitialPlus = !alreadyHasPlus && this.#ui.telInputEl.selectionStart === 0 && e.key === "+";
3782
- const normalisedKey = this.#numerals.normalise(e.key);
3783
- const isNumeric = /^[0-9]$/.test(normalisedKey);
3784
- const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
3785
- const input = this.#ui.telInputEl;
3786
- const selStart = input.selectionStart;
3787
- const selEnd = input.selectionEnd;
3788
- const before = inputValue.slice(0, selStart ?? void 0);
3789
- const after = inputValue.slice(selEnd ?? void 0);
3790
- const newValue = before + normalisedKey + after;
3791
- const newFullNumber = this.#buildFullNumber(newValue);
3792
- let hasExceededMaxLength = false;
3793
- if (intlTelInput.utils && this.#maxCoreNumberLength) {
3794
- const coreNumber = intlTelInput.utils.getCoreNumber(
3795
- newFullNumber,
3796
- this.#selectedCountry?.iso2
3797
- );
3798
- hasExceededMaxLength = coreNumber.length > this.#maxCoreNumberLength;
3799
- }
3800
- const newCountry = this.#resolveCountryChangeFromNumber(newFullNumber);
3801
- const isChangingDialCode = newCountry !== null;
3802
- if (!isAllowedChar || hasExceededMaxLength && !isChangingDialCode && !isInitialPlus) {
3803
- this.#dispatchEvent(EVENTS.STRICT_REJECT, {
3804
- source: "key",
3805
- rejectedInput: e.key,
3806
- reason: !isAllowedChar ? "invalid" : "max-length"
3807
- });
3808
- e.preventDefault();
3809
- }
3810
- };
3811
- this.#ui.telInputEl.addEventListener("keydown", handleKeydownEvent, {
3784
+ this.#ui.telInputEl.addEventListener("keydown", this.#handleKeydownEvent, {
3812
3785
  signal: this.#abortController.signal
3813
3786
  });
3814
3787
  }
3788
+ //* On keydown event: (1) if strictMode then prevent invalid characters, (2) if separateDialCode then handle plus key
3789
+ //* Note that this fires BEFORE the input is updated.
3790
+ #handleKeydownEvent = (e) => {
3791
+ const { strictMode, separateDialCode, allowDropdown, countrySearch } = this.#options;
3792
+ if (!e.key || e.key.length !== 1 || e.altKey || e.ctrlKey || e.metaKey) {
3793
+ return;
3794
+ }
3795
+ if (separateDialCode && allowDropdown && countrySearch && e.key === "+") {
3796
+ e.preventDefault();
3797
+ this.#openDropdownWithPlus();
3798
+ return;
3799
+ }
3800
+ if (!strictMode) {
3801
+ return;
3802
+ }
3803
+ const inputValue = this.#getTelInputValue();
3804
+ const alreadyHasPlus = inputValue.startsWith("+");
3805
+ const isInitialPlus = !alreadyHasPlus && this.#ui.telInputEl.selectionStart === 0 && e.key === "+";
3806
+ const normalisedKey = this.#numerals.normalise(e.key);
3807
+ const isNumeric = /^[0-9]$/.test(normalisedKey);
3808
+ const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
3809
+ const input = this.#ui.telInputEl;
3810
+ const selStart = input.selectionStart;
3811
+ const selEnd = input.selectionEnd;
3812
+ const before = inputValue.slice(0, selStart ?? void 0);
3813
+ const after = inputValue.slice(selEnd ?? void 0);
3814
+ const newValue = before + normalisedKey + after;
3815
+ const newFullNumber = this.#buildFullNumber(newValue);
3816
+ let hasExceededMaxLength = false;
3817
+ if (intlTelInput.utils && this.#maxCoreNumberLength) {
3818
+ const coreNumber = intlTelInput.utils.getCoreNumber(
3819
+ newFullNumber,
3820
+ this.#selectedCountry?.iso2
3821
+ );
3822
+ hasExceededMaxLength = coreNumber.length > this.#maxCoreNumberLength;
3823
+ }
3824
+ const newCountry = this.#resolveCountryChangeFromNumber(newFullNumber);
3825
+ const isChangingDialCode = newCountry !== null;
3826
+ if (!isAllowedChar || hasExceededMaxLength && !isChangingDialCode && !isInitialPlus) {
3827
+ this.#dispatchEvent(EVENTS.STRICT_REJECT, {
3828
+ source: "key",
3829
+ rejectedInput: e.key,
3830
+ reason: !isAllowedChar ? "invalid" : "max-length"
3831
+ });
3832
+ e.preventDefault();
3833
+ }
3834
+ };
3815
3835
  #bindPasteListener() {
3816
3836
  if (!this.#options.strictMode) {
3817
3837
  return;
3818
3838
  }
3819
- const handlePasteEvent = (e) => {
3820
- e.preventDefault();
3821
- const input = this.#ui.telInputEl;
3822
- const selStart = input.selectionStart;
3823
- const selEnd = input.selectionEnd;
3824
- const inputValue = this.#getTelInputValue();
3825
- const before = inputValue.slice(0, selStart ?? void 0);
3826
- const after = inputValue.slice(selEnd ?? void 0);
3827
- const iso2 = this.#selectedCountry?.iso2;
3828
- const pastedRaw = e.clipboardData.getData("text");
3829
- const pasted = this.#numerals.normalise(pastedRaw);
3830
- const initialCharSelected = selStart === 0 && selEnd > 0;
3831
- const allowLeadingPlus = !inputValue.startsWith("+") || initialCharSelected;
3832
- const allowedChars = pasted.replace(REGEX.NON_PLUS_NUMERIC_GLOBAL, "");
3833
- const hasLeadingPlus = allowedChars.startsWith("+");
3834
- const numerics = allowedChars.replace(/\+/g, "");
3835
- const sanitised = hasLeadingPlus && allowLeadingPlus ? `+${numerics}` : numerics;
3836
- let newValue = before + sanitised + after;
3837
- let rejectReason = sanitised !== pasted ? "invalid" : null;
3838
- if (newValue.length > 5 && intlTelInput.utils) {
3839
- let coreNumber = intlTelInput.utils.getCoreNumber(newValue, iso2);
3840
- while (coreNumber.length === 0 && newValue.length > 0) {
3841
- newValue = newValue.slice(0, -1);
3842
- coreNumber = intlTelInput.utils.getCoreNumber(newValue, iso2);
3843
- }
3844
- if (!coreNumber) {
3839
+ this.#ui.telInputEl.addEventListener("paste", this.#handlePasteEvent, {
3840
+ signal: this.#abortController.signal
3841
+ });
3842
+ }
3843
+ #handlePasteEvent = (e) => {
3844
+ e.preventDefault();
3845
+ const input = this.#ui.telInputEl;
3846
+ const selStart = input.selectionStart;
3847
+ const selEnd = input.selectionEnd;
3848
+ const inputValue = this.#getTelInputValue();
3849
+ const before = inputValue.slice(0, selStart ?? void 0);
3850
+ const after = inputValue.slice(selEnd ?? void 0);
3851
+ const iso2 = this.#selectedCountry?.iso2;
3852
+ const pastedRaw = e.clipboardData.getData("text");
3853
+ const pasted = this.#numerals.normalise(pastedRaw);
3854
+ const initialCharSelected = selStart === 0 && selEnd > 0;
3855
+ const allowLeadingPlus = !inputValue.startsWith("+") || initialCharSelected;
3856
+ const allowedChars = pasted.replace(REGEX.NON_PLUS_NUMERIC_GLOBAL, "");
3857
+ const hasLeadingPlus = allowedChars.startsWith("+");
3858
+ const numerics = allowedChars.replace(/\+/g, "");
3859
+ const sanitised = hasLeadingPlus && allowLeadingPlus ? `+${numerics}` : numerics;
3860
+ let newValue = before + sanitised + after;
3861
+ let rejectReason = sanitised !== pasted ? "invalid" : null;
3862
+ if (newValue.length > 5 && intlTelInput.utils) {
3863
+ let coreNumber = intlTelInput.utils.getCoreNumber(newValue, iso2);
3864
+ while (coreNumber.length === 0 && newValue.length > 0) {
3865
+ newValue = newValue.slice(0, -1);
3866
+ coreNumber = intlTelInput.utils.getCoreNumber(newValue, iso2);
3867
+ }
3868
+ if (!coreNumber) {
3869
+ this.#dispatchEvent(EVENTS.STRICT_REJECT, {
3870
+ source: "paste",
3871
+ rejectedInput: pastedRaw,
3872
+ reason: "max-length"
3873
+ });
3874
+ return;
3875
+ }
3876
+ if (this.#maxCoreNumberLength && coreNumber.length > this.#maxCoreNumberLength) {
3877
+ if (input.selectionEnd === inputValue.length) {
3878
+ const trimLength = coreNumber.length - this.#maxCoreNumberLength;
3879
+ newValue = newValue.slice(0, newValue.length - trimLength);
3880
+ rejectReason = "max-length";
3881
+ } else {
3845
3882
  this.#dispatchEvent(EVENTS.STRICT_REJECT, {
3846
3883
  source: "paste",
3847
3884
  rejectedInput: pastedRaw,
@@ -3849,37 +3886,20 @@ var Iti = class _Iti {
3849
3886
  });
3850
3887
  return;
3851
3888
  }
3852
- if (this.#maxCoreNumberLength && coreNumber.length > this.#maxCoreNumberLength) {
3853
- if (input.selectionEnd === inputValue.length) {
3854
- const trimLength = coreNumber.length - this.#maxCoreNumberLength;
3855
- newValue = newValue.slice(0, newValue.length - trimLength);
3856
- rejectReason = "max-length";
3857
- } else {
3858
- this.#dispatchEvent(EVENTS.STRICT_REJECT, {
3859
- source: "paste",
3860
- rejectedInput: pastedRaw,
3861
- reason: "max-length"
3862
- });
3863
- return;
3864
- }
3865
- }
3866
3889
  }
3867
- this.#setTelInputValue(newValue);
3868
- const caretPos = selStart + sanitised.length;
3869
- input.setSelectionRange(caretPos, caretPos);
3870
- input.dispatchEvent(new InputEvent("input", { bubbles: true }));
3871
- if (rejectReason) {
3872
- this.#dispatchEvent(EVENTS.STRICT_REJECT, {
3873
- source: "paste",
3874
- rejectedInput: pastedRaw,
3875
- reason: rejectReason
3876
- });
3877
- }
3878
- };
3879
- this.#ui.telInputEl.addEventListener("paste", handlePasteEvent, {
3880
- signal: this.#abortController.signal
3881
- });
3882
- }
3890
+ }
3891
+ this.#setTelInputValue(newValue);
3892
+ const caretPos = selStart + sanitised.length;
3893
+ input.setSelectionRange(caretPos, caretPos);
3894
+ input.dispatchEvent(new InputEvent("input", { bubbles: true }));
3895
+ if (rejectReason) {
3896
+ this.#dispatchEvent(EVENTS.STRICT_REJECT, {
3897
+ source: "paste",
3898
+ rejectedInput: pastedRaw,
3899
+ reason: rejectReason
3900
+ });
3901
+ }
3902
+ };
3883
3903
  //* Adhere to the input's maxlength attr.
3884
3904
  #truncateToMaxLength(number) {
3885
3905
  const max = Number(this.#ui.telInputEl.getAttribute("maxlength"));
@@ -4521,7 +4541,7 @@ var intlTelInput = Object.assign(
4521
4541
  attachUtils,
4522
4542
  startedLoadingUtils: false,
4523
4543
  startedLoadingAutoCountry: false,
4524
- version: "27.1.2"
4544
+ version: "27.2.0"
4525
4545
  }
4526
4546
  );
4527
4547
  var intlTelInput_default = intlTelInput;
@@ -4576,6 +4596,9 @@ var IntlTelInput = class _IntlTelInput {
4576
4596
  countryChange = new EventEmitter();
4577
4597
  validityChange = new EventEmitter();
4578
4598
  errorCodeChange = new EventEmitter();
4599
+ openCountryDropdown = new EventEmitter();
4600
+ closeCountryDropdown = new EventEmitter();
4601
+ strictReject = new EventEmitter();
4579
4602
  blur = new EventEmitter();
4580
4603
  focus = new EventEmitter();
4581
4604
  keydown = new EventEmitter();
@@ -4590,6 +4613,8 @@ var IntlTelInput = class _IntlTelInput {
4590
4613
  lastEmittedErrorCode;
4591
4614
  // writeValue may be called by Angular forms before utils has loaded; queue it until then
4592
4615
  pendingWriteValue;
4616
+ // if an input event fires before utils has loaded, we defer the update until the promise resolves
4617
+ pendingUpdate = false;
4593
4618
  // eslint-disable-next-line class-methods-use-this
4594
4619
  onChange = () => {
4595
4620
  };
@@ -4599,8 +4624,16 @@ var IntlTelInput = class _IntlTelInput {
4599
4624
  // eslint-disable-next-line class-methods-use-this
4600
4625
  onValidatorChange = () => {
4601
4626
  };
4627
+ handleOpenDropdown = () => this.openCountryDropdown.emit();
4628
+ handleCloseDropdown = () => this.closeCountryDropdown.emit();
4629
+ handleStrictReject = (e) => {
4630
+ this.strictReject.emit(e.detail);
4631
+ };
4602
4632
  ngAfterViewInit() {
4603
4633
  this.iti = intlTelInput_default(this.inputRef.nativeElement, this.buildInitOptions());
4634
+ this.inputRef.nativeElement.addEventListener("open:countrydropdown", this.handleOpenDropdown);
4635
+ this.inputRef.nativeElement.addEventListener("close:countrydropdown", this.handleCloseDropdown);
4636
+ this.inputRef.nativeElement.addEventListener("strict:reject", this.handleStrictReject);
4604
4637
  this.applyInputAttrs();
4605
4638
  if (this.disabled) {
4606
4639
  this.iti.setDisabled(this.disabled);
@@ -4618,6 +4651,12 @@ var IntlTelInput = class _IntlTelInput {
4618
4651
  } else if (this.initialValue) {
4619
4652
  this.iti.setNumber(this.initialValue);
4620
4653
  }
4654
+ if (this.pendingUpdate) {
4655
+ this.pendingUpdate = false;
4656
+ this.handleInput();
4657
+ } else if (this.inputRef.nativeElement.value) {
4658
+ this.onValidatorChange();
4659
+ }
4621
4660
  });
4622
4661
  }
4623
4662
  buildInitOptions() {
@@ -4669,6 +4708,10 @@ var IntlTelInput = class _IntlTelInput {
4669
4708
  if (!this.iti) {
4670
4709
  return;
4671
4710
  }
4711
+ if (!intlTelInput_default.utils) {
4712
+ this.pendingUpdate = true;
4713
+ return;
4714
+ }
4672
4715
  const num = this.iti.getNumber() ?? "";
4673
4716
  const countryIso = this.iti.getSelectedCountryData()?.iso2 ?? "";
4674
4717
  let hasChanged = false;
@@ -4733,6 +4776,9 @@ var IntlTelInput = class _IntlTelInput {
4733
4776
  return this.inputRef.nativeElement;
4734
4777
  }
4735
4778
  ngOnDestroy() {
4779
+ this.inputRef.nativeElement.removeEventListener("open:countrydropdown", this.handleOpenDropdown);
4780
+ this.inputRef.nativeElement.removeEventListener("close:countrydropdown", this.handleCloseDropdown);
4781
+ this.inputRef.nativeElement.removeEventListener("strict:reject", this.handleStrictReject);
4736
4782
  this.iti?.destroy();
4737
4783
  }
4738
4784
  ignoredInputAttrs = /* @__PURE__ */ new Set([
@@ -4783,7 +4829,7 @@ var IntlTelInput = class _IntlTelInput {
4783
4829
  }
4784
4830
  // ============ Validator Implementation ============
4785
4831
  validate(_control) {
4786
- if (!this.iti || !this.iti.getNumber()) {
4832
+ if (!this.iti || !intlTelInput_default.utils || !this.iti.getNumber()) {
4787
4833
  return null;
4788
4834
  }
4789
4835
  const isValid = this.usePreciseValidation ? this.iti.isValidNumberPrecise() : this.iti.isValidNumber();
@@ -4809,7 +4855,7 @@ var IntlTelInput = class _IntlTelInput {
4809
4855
  let _t;
4810
4856
  i0.\u0275\u0275queryRefresh(_t = i0.\u0275\u0275loadQuery()) && (ctx.inputRef = _t.first);
4811
4857
  }
4812
- }, inputs: { initialValue: "initialValue", usePreciseValidation: "usePreciseValidation", inputAttributes: "inputAttributes", disabled: "disabled", readonly: "readonly", allowDropdown: "allowDropdown", allowedNumberTypes: "allowedNumberTypes", allowNumberExtensions: "allowNumberExtensions", allowPhonewords: "allowPhonewords", autoPlaceholder: "autoPlaceholder", containerClass: "containerClass", countryNameLocale: "countryNameLocale", countryOrder: "countryOrder", countrySearch: "countrySearch", customPlaceholder: "customPlaceholder", dropdownAlwaysOpen: "dropdownAlwaysOpen", dropdownContainer: "dropdownContainer", excludeCountries: "excludeCountries", fixDropdownWidth: "fixDropdownWidth", formatAsYouType: "formatAsYouType", formatOnDisplay: "formatOnDisplay", geoIpLookup: "geoIpLookup", hiddenInput: "hiddenInput", i18n: "i18n", initialCountry: "initialCountry", loadUtils: "loadUtils", nationalMode: "nationalMode", onlyCountries: "onlyCountries", placeholderNumberType: "placeholderNumberType", searchInputClass: "searchInputClass", separateDialCode: "separateDialCode", showFlags: "showFlags", strictMode: "strictMode", useFullscreenPopup: "useFullscreenPopup" }, outputs: { numberChange: "numberChange", countryChange: "countryChange", validityChange: "validityChange", errorCodeChange: "errorCodeChange", blur: "blur", focus: "focus", keydown: "keydown", keyup: "keyup", paste: "paste", click: "click" }, features: [i0.\u0275\u0275ProvidersFeature([
4858
+ }, inputs: { initialValue: "initialValue", usePreciseValidation: "usePreciseValidation", inputAttributes: "inputAttributes", disabled: "disabled", readonly: "readonly", allowDropdown: "allowDropdown", allowedNumberTypes: "allowedNumberTypes", allowNumberExtensions: "allowNumberExtensions", allowPhonewords: "allowPhonewords", autoPlaceholder: "autoPlaceholder", containerClass: "containerClass", countryNameLocale: "countryNameLocale", countryOrder: "countryOrder", countrySearch: "countrySearch", customPlaceholder: "customPlaceholder", dropdownAlwaysOpen: "dropdownAlwaysOpen", dropdownContainer: "dropdownContainer", excludeCountries: "excludeCountries", fixDropdownWidth: "fixDropdownWidth", formatAsYouType: "formatAsYouType", formatOnDisplay: "formatOnDisplay", geoIpLookup: "geoIpLookup", hiddenInput: "hiddenInput", i18n: "i18n", initialCountry: "initialCountry", loadUtils: "loadUtils", nationalMode: "nationalMode", onlyCountries: "onlyCountries", placeholderNumberType: "placeholderNumberType", searchInputClass: "searchInputClass", separateDialCode: "separateDialCode", showFlags: "showFlags", strictMode: "strictMode", useFullscreenPopup: "useFullscreenPopup" }, outputs: { numberChange: "numberChange", countryChange: "countryChange", validityChange: "validityChange", errorCodeChange: "errorCodeChange", openCountryDropdown: "openCountryDropdown", closeCountryDropdown: "closeCountryDropdown", strictReject: "strictReject", blur: "blur", focus: "focus", keydown: "keydown", keyup: "keyup", paste: "paste", click: "click" }, features: [i0.\u0275\u0275ProvidersFeature([
4813
4859
  {
4814
4860
  provide: NG_VALUE_ACCESSOR,
4815
4861
  useExisting: forwardRef(() => _IntlTelInput),
@@ -4953,6 +4999,12 @@ var IntlTelInput = class _IntlTelInput {
4953
4999
  type: Output
4954
5000
  }], errorCodeChange: [{
4955
5001
  type: Output
5002
+ }], openCountryDropdown: [{
5003
+ type: Output
5004
+ }], closeCountryDropdown: [{
5005
+ type: Output
5006
+ }], strictReject: [{
5007
+ type: Output
4956
5008
  }], blur: [{
4957
5009
  type: Output
4958
5010
  }], focus: [{
@@ -4968,7 +5020,7 @@ var IntlTelInput = class _IntlTelInput {
4968
5020
  }] });
4969
5021
  })();
4970
5022
  (() => {
4971
- (typeof ngDevMode === "undefined" || ngDevMode) && i0.\u0275setClassDebugInfo(IntlTelInput, { className: "IntlTelInput", filePath: "IntlTelInput.ts", lineNumber: 62 });
5023
+ (typeof ngDevMode === "undefined" || ngDevMode) && i0.\u0275setClassDebugInfo(IntlTelInput, { className: "IntlTelInput", filePath: "IntlTelInput.ts", lineNumber: 68 });
4972
5024
  })();
4973
5025
  var IntlTelInput_default = IntlTelInput;
4974
5026
  export {