intl-tel-input 25.10.11 → 25.11.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/README.md CHANGED
@@ -1,16 +1,20 @@
1
1
  # International Telephone Input [![CI](https://github.com/jackocnr/intl-tel-input/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/jackocnr/intl-tel-input/actions/workflows/ci.yml) <img src="https://img.shields.io/github/package-json/v/jackocnr/intl-tel-input.svg" alt="version"/> <img src="https://img.shields.io/npm/dm/intl-tel-input.svg" alt="downloads"/>
2
2
 
3
- <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/vue-icon.png" alt="Vue logo" width="16px" /> NEWS: we now have our own <a href="https://github.com/jackocnr/intl-tel-input/tree/master/vue">Vue component</a>!
3
+ <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/vue-icon.png" alt="Vue logo" width="16" /> NEWS: we now have our own <a href="https://github.com/jackocnr/intl-tel-input/tree/master/vue">Vue component</a>!
4
4
 
5
- <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/react.webp" alt="React logo" width="16px" /> NEWS: we now have our own <a href="https://github.com/jackocnr/intl-tel-input/tree/master/react">React component</a>! Play with it on <a href="https://intl-tel-input.com/storybook/?path=/docs/intltelinput--vanilla">Storybook</a>.
5
+ <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/react.webp" alt="React logo" width="16" /> NEWS: we now have our own <a href="https://github.com/jackocnr/intl-tel-input/tree/master/react">React component</a>! Play with it on <a href="https://intl-tel-input.com/storybook/?path=/docs/intltelinput--vanilla">Storybook</a>.
6
6
 
7
- <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/angular.png" alt="Angular logo" width="16px" /> NEWS: we now have our own <a href="https://github.com/jackocnr/intl-tel-input/tree/master/angular">Angular component</a>!
7
+ <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/angular.png" alt="Angular logo" width="16" /> NEWS: we now have our own <a href="https://github.com/jackocnr/intl-tel-input/tree/master/angular">Angular component</a>!
8
8
 
9
9
  🗣️ NEWS: we now provide [translations](#translations) in over 30 languages! [See them in action](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--i18n).
10
10
 
11
11
  International Telephone Input is a JavaScript plugin for entering and validating international telephone numbers. It takes a regular input field, adds a searchable country dropdown, auto-detects the user's country, displays a relevant placeholder number, formats the number as you type, and provides comprehensive validation methods. React, Vue and Angular components are also included.
12
12
 
13
- <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/vanilla2.png" alt="Screenshot" width="265px" height="273px" />
13
+ <picture>
14
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/vanilla-dark.png">
15
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/vanilla-light.png">
16
+ <img width="263" height="269" alt="Plugin screenshot showing country dropdown open" src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/vanilla-light.png">
17
+ </picture>
14
18
 
15
19
  If you find the plugin helpful, please consider [supporting the project](https://github.com/sponsors/jackocnr).
16
20
 
@@ -47,24 +51,24 @@ We now provide React, Vue and Angular components alongside the regular JavaScrip
47
51
  You can view [a live demo](https://intl-tel-input.com) and see some examples of how to use the various options. Alternatively, try it for yourself by downloading the project and opening demo.html in a browser.
48
52
 
49
53
  ## Mobile
50
- By default, on mobile devices we show a fullscreen popup instead of the inline dropdown, to make better use of the limited screen space. This is similar to how a native `<select>` element works. You can control this behaviour with the `useFullscreenPopup` option. The popup can be closed by either selecting a country from the list or by tapping on the grey area at the sides. [See example](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--usefullscreenpopup) (using the React component).
54
+ By default, on mobile devices, we show a fullscreen popup instead of the inline dropdown to make better use of the limited screen space. This is similar to how a native `<select>` element works. You can control this behaviour with the `useFullscreenPopup` option. The popup can be closed by either selecting a country from the list or by tapping on the grey area on the sides. [See example](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--usefullscreenpopup) (using the React component).
51
55
 
52
- <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/mobile2.png" alt="Mobile screenshot" width="270px" height="512px" />
56
+ <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/mobile2.png" alt="Mobile screenshot" width="270" height="512" />
53
57
 
54
58
  ## Features
55
59
  * Automatically select the user's current country using an IP lookup
56
60
  * Automatically set the input placeholder to an example number for the selected country
57
61
  * Navigate the country dropdown by typing a country's name, or using the up/down keys
58
62
  * Automatically format the number as the user types
59
- * Optionally only allow numeric characters and cap the number at the maximum valid length
60
- * The user types their national number and the plugin gives you the full standardised international number
63
+ * Optionally, only allow numeric characters and cap the number at the maximum valid length
64
+ * The user types their national number, and the plugin gives you the full standardised international number
61
65
  * Number validation, including specific error types
62
66
  * High-resolution flag images
63
67
  * Accessibility provided via ARIA tags
64
68
  * Typescript type definitions included
65
- * Easily customise styles by overriding CSS variables
66
- * React, Vue and Angular components also included
67
- * Translations for country names (etc) provided in many different languages
69
+ * Easily customise styles by overriding CSS variables, e.g. support dark mode
70
+ * React, Vue, and Angular components also included
71
+ * Translations for country names (etc) provided in many different languages, and support for RTL layout
68
72
  * Lots of initialisation options for customisation, as well as instance methods/events for interaction
69
73
 
70
74
  ## Browser Compatibility
@@ -77,21 +81,21 @@ _Note: We have now dropped support for all versions of Internet Explorer because
77
81
  ## Getting Started (Using a CDN)
78
82
  1. Add the CSS
79
83
  ```html
80
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/intl-tel-input@25.10.11/build/css/intlTelInput.css">
84
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/intl-tel-input@25.11.0/build/css/intlTelInput.css">
81
85
  ```
82
86
 
83
87
  2. Add the plugin script and initialise it on your input element
84
88
  ```html
85
- <script src="https://cdn.jsdelivr.net/npm/intl-tel-input@25.10.11/build/js/intlTelInput.min.js"></script>
89
+ <script src="https://cdn.jsdelivr.net/npm/intl-tel-input@25.11.0/build/js/intlTelInput.min.js"></script>
86
90
  <script>
87
91
  const input = document.querySelector("#phone");
88
92
  window.intlTelInput(input, {
89
- loadUtils: () => import("https://cdn.jsdelivr.net/npm/intl-tel-input@25.10.11/build/js/utils.js"),
93
+ loadUtils: () => import("https://cdn.jsdelivr.net/npm/intl-tel-input@25.11.0/build/js/utils.js"),
90
94
  });
91
95
  </script>
92
96
  ```
93
97
 
94
- ## Getting Started (Using a bundler e.g. Webpack)
98
+ ## Getting Started (Using a bundler, e.g. Webpack)
95
99
  1. Install with npm: `npm install intl-tel-input --save` or yarn: `yarn add intl-tel-input`
96
100
 
97
101
  2. Import the CSS: `import 'intl-tel-input/build/css/intlTelInput.css';`
@@ -163,11 +167,11 @@ When you initialise the plugin, the first argument is the input element, and the
163
167
 
164
168
  **allowDropdown**
165
169
  Type: `Boolean` Default: `true`
166
- Whether or not to allow the dropdown. If disabled, there is no dropdown arrow, and the selected country is not clickable. Also, if showFlags is enabled, we display the selected flag on the right instead because it is just a marker of state. Note that if `separateDialCode` is enabled, `allowDropdown` is forced to `true` as the dropdown is required when the user types "+" in this case. Play with this option on [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--allowdropdown) (using the React component).
170
+ Whether or not to allow the dropdown. If disabled, there is no dropdown arrow, and the selected country is not clickable. Also, if showFlags is enabled, we display the selected flag on the right instead, because it is just a marker of state. Note that if `separateDialCode` is enabled, `allowDropdown` is forced to `true` as the dropdown is required when the user types "+" in this case. Play with this option on [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--allowdropdown) (using the React component).
167
171
 
168
172
  **allowPhonewords**
169
173
  Type: `Boolean` Default: `false`
170
- Whether or not the validation methods return `true` for numbers containing phonewords e.g. "+1 702 FLOWERS".
174
+ Whether or not the validation methods return `true` for numbers containing phonewords, e.g. "+1 702 FLOWERS".
171
175
 
172
176
  **autoPlaceholder**
173
177
  Type: `String` Default: `"polite"`
@@ -179,7 +183,7 @@ Additional classes to add to the (injected) wrapper `<div>`.
179
183
 
180
184
  **countryOrder**
181
185
  Type: `Array` Default: `null`
182
- Specify the ordering for the country list with an array of iso2 country codes. Any omitted countries will appear after those specified, in alphabetical order e.g. setting `countryOrder` to `["jp", "kr"]` will result in the list: Japan, South Korea, Afghanistan, Albania, Algeria etc...
186
+ Specify the ordering for the country list with an array of iso2 country codes. Any omitted countries will appear after those specified, in alphabetical order, e.g. setting `countryOrder` to `["jp", "kr"]` will result in the list: Japan, South Korea, Afghanistan, Albania, Algeria etc...
183
187
 
184
188
  **countrySearch**
185
189
  Type: `Boolean` Default: `true`
@@ -197,11 +201,11 @@ intlTelInput(input, {
197
201
 
198
202
  **dropdownContainer**
199
203
  Type: `Node` Default: `null`
200
- Expects a node e.g. `document.body`. Instead of putting the country dropdown markup next to the input, append it to the specified node, and it will then be positioned next to the input using JavaScript (using `position: fixed`). This is useful when the input is inside a container with `overflow: hidden`. Note that the positioning is broken by scrolling, so the dropdown will automatically close on the `window` scroll event.
204
+ Expects a node, e.g. `document.body`. Instead of putting the country dropdown markup next to the input, append it to the specified node, and it will then be positioned next to the input using JavaScript (using `position: fixed`). This is useful when the input is inside a container with `overflow: hidden`. Note that the positioning is broken by scrolling, so the dropdown will automatically close on the `window` scroll event.
201
205
 
202
206
  **excludeCountries**
203
207
  Type: `Array` Default: `[]`
204
- In the dropdown, display all countries except the ones you specify here. Play with this option on [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--excludecountries) (using the React component).
208
+ In the dropdown, display all countries except the ones you specify here. Play with this option on [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--excludecountries) (using the React component). Also see: `onlyCountries` option.
205
209
 
206
210
  **fixDropdownWidth**
207
211
  Type: `Boolean` Default: `true`
@@ -235,7 +239,7 @@ _Note that the `failure` callback must be called in the event of an error, hence
235
239
 
236
240
  **hiddenInput**
237
241
  Type: `Function` Default: `null`
238
- Allows the creation of hidden input fields within a form, which, on submit, get populated with the (1) full international telephone number and (2) the selected country code. It accepts a function that receives the name of the main telephone input as an argument. This function should return an object with `phone` and (optionally) `country` properties to specify the names of the hidden inputs for the phone number and country code, respectively. This is useful for non-Ajax form submissions to ensure the full international number and country code are captured, especially when `nationalMode` is enabled.
242
+ Allows the creation of hidden input fields within a form, which, on submit, get populated with (1) the full international telephone number and (2) the selected country code. It accepts a function that receives the name of the main telephone input as an argument. This function should return an object with `phone` and (optionally) `country` properties to specify the names of the hidden inputs for the phone number and country code, respectively. This is useful for old-fashioned, page-load form submissions to ensure the full international number and country code are captured, especially when `nationalMode` is enabled.
239
243
 
240
244
  ***Note**: This feature requires the input to be inside a `<form>` element, as it listens for the `submit` event on the closest form element. Also note that since this uses `getNumber` internally, firstly it requires the [utils script to be loaded](#loading-the-utilities-script), and secondly, it expects a valid number and so will only work correctly if you have used `isValidNumber` to validate the number before allowing the form submit to go through.
241
245
 
@@ -318,27 +322,26 @@ intlTelInput(input, {
318
322
 
319
323
  **initialCountry**
320
324
  Type: `String` Default: `""`
321
- Set the initial country selection by specifying its country code e.g. `"us"` for the United States. (Be careful not to do this unless you are sure of the user's country, as it can lead to tricky issues if set incorrectly and the user auto-fills their national number and submits the form without checking - in certain cases, this can pass validation and you can end up storing a number with the wrong dial code). You can also set `initialCountry` to `"auto"`, which will look up the user's country based on their IP address (requires the `geoIpLookup` option - [see example](https://intl-tel-input.com/examples/lookup-country.html)). Note that however you use `initialCountry`, it will not update the country selection if the input already contains a number with an international dial code.
325
+ Set the initial country selection by specifying its country code, e.g. `"us"` for the United States. (Be careful not to do this unless you are sure of the user's country, as it can lead to tricky issues if set incorrectly and the user auto-fills their national number and submits the form without checking - in certain cases, this can pass validation and you can end up storing a number with the wrong dial code). You can also set `initialCountry` to `"auto"`, which will look up the user's country based on their IP address (requires the `geoIpLookup` option - [see example](https://intl-tel-input.com/examples/lookup-country.html)). Note: however you use `initialCountry`, it will not update the country selection if the input already contains a number with an international dial code.
322
326
 
323
327
  **loadUtils**
324
- Type: `() => Promise<module>` Default: `null` Example: `() => import("/path/to/utils.js")`
325
-
326
- This is one way to lazy load the included utils.js (to enable formatting/validation etc) - see [Loading The Utilities Script](#loading-the-utilities-script) for more options.
328
+ Type: `() => Promise<module>` Default: `null`
329
+ This is one way to lazy load the included utils.js (to enable formatting/validation, etc) - see [Loading The Utilities Script](#loading-the-utilities-script) for more options.
327
330
 
328
331
  The `loadUtils` option takes a function which returns a Promise which resolves to the utils module. You can `import` the utils module in different ways: (A) from a CDN, (B) from your own hosted version of [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js), or (C) if you use a bundler like Webpack, Vite or Parcel, you can import it directly from the package.
329
332
 
330
333
  ```js
331
334
  // (A) import utils module from a CDN
332
335
  intlTelInput(htmlInputElement, {
333
- loadUtils: () => import("https://cdn.jsdelivr.net/npm/intl-tel-input@25.10.11/build/js/utils.js"),
336
+ loadUtils: () => import("https://cdn.jsdelivr.net/npm/intl-tel-input@25.11.0/build/js/utils.js"),
334
337
  });
335
338
 
336
339
  // (B) import utils module from your own hosted version of utils.js
337
340
  intlTelInput(htmlInputElement, {
338
- loadUtils: () => import("https://my-domain.com/path/to/utils.js"),
341
+ loadUtils: () => import("/path/to/utils.js"),
339
342
  });
340
343
 
341
- // (C) if your bundler supports it, you can import utils module directly from the package
344
+ // (C) if your bundler supports it, you can import the utils module directly from the package
342
345
  intlTelInput(htmlInputElement, {
343
346
  loadUtils: () => import("intl-tel-input/utils"),
344
347
  });
@@ -346,15 +349,15 @@ intlTelInput(htmlInputElement, {
346
349
 
347
350
  The module is only loaded when you initialise the plugin, and additionally, only when the page has finished loading (on the window load event) to prevent blocking (the script is ~260KB). When instantiating the plugin, a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) object is returned under the `promise` instance property, so you can do something like `iti.promise.then(callback)` to know when initialisation requests like this have finished. See [Utilities Script](#utilities-script) for more information.
348
351
 
349
- If you want more control over when this file is lazy loaded, you can manually invoke the `attachUtils` static method whenever you like, instead of using the `loadUtils` initialisation option.
352
+ If you want more control over when this file is lazy-loaded, you can manually invoke the `attachUtils` static method whenever you like, instead of using the `loadUtils` initialisation option.
350
353
 
351
354
  **nationalMode**
352
355
  Type: `Boolean` Default: `true`
353
- Format numbers in the national format, rather than the international format. This applies to placeholder numbers, and when displaying users' existing numbers. Note that it's fine for users to type their numbers in national format - as long as they have selected the right country, you can use `getNumber` to extract a full international number - [see example](https://intl-tel-input.com/examples/national-mode.html). It is recommended to leave this option enabled, to encourage users to enter their numbers in national format as this is usually more familiar to them and so it creates a better user experience.
356
+ Format numbers in the national format, rather than the international format. This applies to placeholder numbers and when displaying users' existing numbers. Note that it's fine for users to type their numbers in national format - as long as they have selected the right country, you can use `getNumber` to extract a full international number - [see example](https://intl-tel-input.com/examples/national-mode.html). It is recommended to leave this option enabled to encourage users to enter their numbers in national format, as this is usually more familiar to them, and so it creates a better user experience.
354
357
 
355
358
  **onlyCountries**
356
359
  Type: `Array` Default: `[]`
357
- In the dropdown, display only the countries you specify - [see example](https://intl-tel-input.com/examples/only-countries.html).
360
+ In the dropdown, display only the countries you specify - [see example](https://intl-tel-input.com/examples/only-countries.html). Also see: `excludeCountries` option.
358
361
 
359
362
  **placeholderNumberType**
360
363
  Type: `String` Default: `"MOBILE"`
@@ -362,14 +365,14 @@ Specify [one of the keys](https://github.com/jackocnr/intl-tel-input/blob/master
362
365
 
363
366
  **showFlags**
364
367
  Type: `Boolean` Default: `true`
365
- Set this to false to hide the flags e.g. for political reasons. Instead, it will show a generic globe icon. Play with this option on [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--showflags) (using the React component).
368
+ Set this to false to hide the flags, e.g. for political reasons. Instead, it will show a generic globe icon. Play with this option on [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--showflags) (using the React component).
366
369
 
367
370
  **separateDialCode**
368
371
  Type: `Boolean` Default: `false`
369
- Display the selected country's international dial code next to the input, so it looks like it's part of the typed number. Since the user cannot edit the displayed dial code, they may try to type a new one - in this case, to avoid having two dial codes next to each other, we automatically open the country dropdown and put the new dial code in the search input instead. So if they type +54, then Argentina will be highlighted in the dropdown and they can simply press Enter to select it, updating the displayed dial code (this feature requires `allowDropdown` and `countrySearch` to be enabled). Play with this option on [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--separatedialcode) (using the React component).
372
+ Display the selected country's international dial code next to the input, so it looks like it's part of the typed number. Since the user cannot edit the displayed dial code, they may try to type a new one - in this case, to avoid having two dial codes next to each other, we automatically open the country dropdown and put the new dial code in the search input instead. So if they type +54, then Argentina will be highlighted in the dropdown, and they can simply press Enter to select it, updating the displayed dial code (this feature requires `allowDropdown` and `countrySearch` to be enabled). Play with this option on [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--separatedialcode) (using the React component).
370
373
  __Note: if the user enters their number with autofill or by copying and pasting it, and their number includes the international dial code, then this will be shown twice__
371
374
 
372
- <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/separate-dial-code4.png" width="267px" height="51px" alt="Separate Dial Code">
375
+ <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/separate-dial-code4.png" width="267" height="51" alt="Separate Dial Code">
373
376
 
374
377
  **strictMode**
375
378
  Type: `Boolean` Default: `false`
@@ -384,7 +387,7 @@ Type: `String[]` Default: `["MOBILE"]`
384
387
  Specify an array of [the keys](https://github.com/jackocnr/intl-tel-input/blob/master/src/js/utils.js#L198) from the enum `intlTelInput.utils.numberType` to set the number type(s) to enforce during validation, as well as the number length to enforce with `strictMode`. Set it to `null` to not enforce any particular type. By default, it's set to `["MOBILE"]` so `isValidNumber` will only return `true` for mobile numbers. Alternatively, you could set it to, for example, `["TOLL_FREE", "PREMIUM_RATE"]` to get `isValidNumber` to return `true` for only those kinds of numbers.
385
388
 
386
389
  ## Instance Methods
387
- In these examples, `iti` refers to the plugin instance which gets returned when you initialise the plugin e.g.
390
+ In these examples, `iti` refers to the plugin instance which gets returned when you initialise the plugin, e.g.
388
391
  ```js
389
392
  const iti = intlTelInput(input);
390
393
  ```
@@ -400,7 +403,7 @@ Get the extension from the current number. Requires the [utils script to be load
400
403
  ```js
401
404
  const extension = iti.getExtension();
402
405
  ```
403
- Returns a string e.g. if the input value was `"(702) 555-5555 ext. 1234"`, this would return `"1234"`
406
+ Returns a string, e.g. if the input value was `"(702) 555-5555 ext. 1234"`, this would return `"1234"`
404
407
 
405
408
  **getNumber**
406
409
  Get the current number in the given format (defaults to [E.164 standard](https://en.wikipedia.org/wiki/E.164)). The different formats are available in the enum `intlTelInput.utils.numberFormat` - which you can see [here](https://github.com/jackocnr/intl-tel-input/blob/master/src/js/utils.js#L153). Requires the [utils script to be loaded](#loading-the-utilities-script). _Note that even if `nationalMode` is enabled, this can still return a full international number. Also note that this method expects a valid number, and so should only be used after validation._
@@ -412,17 +415,17 @@ const number = iti.getNumber(intlTelInput.utils.numberFormat.E164);
412
415
  Returns a string e.g. `"+17024181234"`
413
416
 
414
417
  **getNumberType**
415
- Get the type (fixed-line/mobile/toll-free etc) of the current number. Requires the [utils script to be loaded](#loading-the-utilities-script).
418
+ Get the type (fixed-line/mobile/toll-free, etc) of the current number. Requires the [utils script to be loaded](#loading-the-utilities-script).
416
419
  ```js
417
420
  const numberType = iti.getNumberType();
418
421
  ```
419
- Returns an integer, which you can match against the [various options](https://github.com/jackocnr/intl-tel-input/blob/master/src/js/utils.js#L162) in the enum `intlTelInput.utils.numberType` e.g.
422
+ Returns an integer, which you can match against the [various options](https://github.com/jackocnr/intl-tel-input/blob/master/src/js/utils.js#L162) in the enum `intlTelInput.utils.numberType`, e.g.
420
423
  ```js
421
424
  if (numberType === intlTelInput.utils.numberType.MOBILE) {
422
425
  // is a mobile number
423
426
  }
424
427
  ```
425
- _Note that in the US there's no way to differentiate between fixed-line and mobile numbers, so instead it will return `FIXED_LINE_OR_MOBILE`._
428
+ _Note that in the US, there's no way to differentiate between fixed-line and mobile numbers, so instead it will return `FIXED_LINE_OR_MOBILE`._
426
429
 
427
430
  **getSelectedCountryData**
428
431
  Get the country data for the currently selected country.
@@ -443,7 +446,7 @@ Get more information about a validation error. Requires the [utils script to be
443
446
  ```js
444
447
  const error = iti.getValidationError();
445
448
  ```
446
- Returns an integer, which you can match against the [various options](https://github.com/jackocnr/intl-tel-input/blob/master/src/js/utils.js#L178) in the enum `intlTelInput.utils.validationError` e.g.
449
+ Returns an integer, which you can match against the [various options](https://github.com/jackocnr/intl-tel-input/blob/master/src/js/utils.js#L178) in the enum `intlTelInput.utils.validationError`, e.g.
447
450
  ```js
448
451
  if (error === intlTelInput.utils.validationError.TOO_SHORT) {
449
452
  // the number is too short
@@ -460,14 +463,14 @@ Returns: `true`/`false`
460
463
 
461
464
  **isValidNumberPrecise** ⚠️ DANGEROUS
462
465
  (Note: only returns `true` for valid <ins>mobile numbers</ins> by default - see `validationNumberTypes`)
463
- Check if the current number is valid using precise matching rules for each country/area code etc - [see example](https://intl-tel-input.com/examples/validation.html). Note that these rules change each month for various countries around the world, so you need to constantly keep the plugin up-to-date (e.g. via an automated script) else <ins>you will start rejecting valid numbers</ins>. For a simpler and more future-proof form of validation, see `isValidNumber` above. If validation fails, you can use `getValidationError` to get more information. Requires the [utils script to be loaded](#loading-the-utilities-script).
466
+ Check if the current number is valid using precise matching rules for each country/area code, etc - [see example](https://intl-tel-input.com/examples/validation.html). Note that these rules change each month for various countries around the world, so you need to constantly keep the plugin up-to-date (e.g. via an automated script) else <ins>you will start rejecting valid numbers</ins>. For a simpler and more future-proof form of validation, see `isValidNumber` above. If validation fails, you can use `getValidationError` to get more information. Requires the [utils script to be loaded](#loading-the-utilities-script).
464
467
  ```js
465
468
  const isValid = iti.isValidNumberPrecise();
466
469
  ```
467
470
  Returns: `true`/`false`
468
471
 
469
472
  **setCountry**
470
- Change the selected country. It should be rare, if ever, that you need to do this, as the selected country gets updated automatically when calling `setNumber` and passing a number including an international dial code, which is the recommended usage. Note you can omit the country code argument to set the country to the default empty (globe) state. _Note that if `formatOnDisplay` is enabled, this will attempt to format the number to either national or international format according to the `nationalMode` option._
473
+ Change the selected country. It should be rare, if ever, that you need to do this, as the selected country gets updated automatically when calling `setNumber` and passing a number including an international dial code, which is the recommended usage. Note, you can omit the country code argument to set the country to the default empty (globe) state. _Note that if `formatOnDisplay` is enabled, this will attempt to format the number to either national or international format according to the `nationalMode` option._
471
474
  ```js
472
475
  iti.setCountry("gb");
473
476
  ```
@@ -493,7 +496,7 @@ iti.setPlaceholderNumberType("FIXED_LINE");
493
496
  ## Static Methods
494
497
 
495
498
  **getCountryData**
496
- Retrieve the plugin's country data - either to re-use elsewhere e.g. to generate your own country dropdown - [see example](https://intl-tel-input.com/examples/country-sync.html), or alternatively, you could use it to modify the country data. Note that any modifications must be done before initialising the plugin.
499
+ Retrieve the plugin's country data - either to re-use elsewhere, e.g. to generate your own country dropdown - [see example](https://intl-tel-input.com/examples/country-sync.html), or alternatively, you could use it to modify the country data. Note that any modifications must be done before initialising the plugin.
497
500
  ```js
498
501
  const countryData = intlTelInput.getCountryData();
499
502
  ```
@@ -525,7 +528,7 @@ intlTelInput.attachUtils(loadUtils);
525
528
  You can listen for the following events triggered on the input element.
526
529
 
527
530
  **countrychange**
528
- This is triggered when the selected country is updated e.g. if the user selects a country from the dropdown, or they type a different dial code into the input, or you call `setCountry` etc.
531
+ This is triggered when the selected country is updated, e.g. if the user selects a country from the dropdown, or they type a different dial code into the input, or you call `setCountry` etc.
529
532
  ```js
530
533
  input.addEventListener("countrychange", () => {
531
534
  // do something with iti.getSelectedCountryData()
@@ -542,7 +545,7 @@ This is triggered when the user closes the dropdown.
542
545
  ## Theming / Dark Mode
543
546
  There are lots of CSS variables available for theming. See [intlTelInput.scss](https://github.com/jackocnr/intl-tel-input/blob/master/src/css/intlTelInput.scss) for the full list.
544
547
 
545
- As for the empty state (globe icon), the default version is dark grey, and we also provide a "light" version, that should work better with a dark theme. Alternatively, it's easy to [re-generate the globe icon](https://free-icon-rainbow.com/international-call-free-icon) in whatever colour you need for your theme. We recommend you download it in the highest resolution possible, and then scale the image down to the required sizes (20px wide for the default version and 40px wide for the @2x version).
548
+ As for the empty state (globe icon), the default version is dark grey, and we also provide a "light" version that should work better with a dark theme. Alternatively, it's easy to [re-generate the globe icon](https://free-icon-rainbow.com/international-call-free-icon) in whatever colour you need for your theme. We recommend you download it in the highest resolution possible, and then scale the image down to the required sizes (20px wide for the default version and 40px wide for the @2x version).
546
549
 
547
550
  Dark mode example (with screenshot below):
548
551
  ```css
@@ -559,7 +562,7 @@ Dark mode example (with screenshot below):
559
562
  }
560
563
  ```
561
564
 
562
- NOTE: this assumes you already have your own dark mode styling in place for general body/input styling e.g. something like this:
565
+ NOTE: this assumes you already have your own dark mode styling in place for general body/input styling, e.g. something like this:
563
566
 
564
567
  ```css
565
568
  @media (prefers-color-scheme: dark) {
@@ -577,7 +580,7 @@ NOTE: this assumes you already have your own dark mode styling in place for gene
577
580
  ```
578
581
 
579
582
  Example:
580
- <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/dark-mode2.png" alt="Screenshot" width="264px" height="272px" />
583
+ <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/vanilla-dark.png" alt="Screenshot" width="263" height="269" />
581
584
 
582
585
  ## Translations
583
586
  We provide [translations](https://github.com/jackocnr/intl-tel-input/tree/master/build/js/i18n) for the 200+ country names, as well as other user interface text (e.g. the placeholder text for the country search input) in over 30 languages. See the `i18n` option for details on how to use them. [See them in action](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--i18n).
@@ -601,46 +604,46 @@ To recompile the utils script yourself (e.g. to update the version of libphonenu
601
604
  ## Loading The Utilities Script
602
605
  See [v25 discussion](https://github.com/jackocnr/intl-tel-input/discussions/1842).
603
606
 
604
- The utils script provides lots of great functionality (see above section), but comes at the cost of increased filesize (~260KB). There are two main ways to load the utils script, depending on whether you're concerned about filesize or not.
607
+ The utils script provides lots of great functionality (see the above section), but comes at the cost of increased filesize (~260KB). There are two main ways to load the utils script, depending on whether you're concerned about filesize or not.
605
608
 
606
609
  **Option 1: intlTelInputWithUtils**
607
- If you're not concerned about filesize (e.g. you're lazy loading this script), the easiest thing to do is to just use the full bundle (`/build/js/intlTelInputWithUtils.js`), which comes with the utils script included. This script can be used exactly like the main intlTelInput.js - so it can either be loaded directly onto the page (which defines `window.intlTelInput` like usual), or it can be imported like so: `import intlTelInput from "intl-tel-input/intlTelInputWithUtils"`.
610
+ If you're not concerned about filesize (e.g. you're lazy loading the main plugin script), the easiest thing to do is to just use the full bundle (`/build/js/intlTelInputWithUtils.js`), which comes with the utils script included. This script can be used exactly like the main intlTelInput.js - so it can either be loaded directly onto the page (which defines `window.intlTelInput` like usual), or it can be imported like so: `import intlTelInput from "intl-tel-input/intlTelInputWithUtils"`.
608
611
 
609
612
  **Option 2: loadUtils**
610
613
  If you *are* concerned about filesize, you can lazy load the utils module when the plugin initialises, using the `loadUtils` initialisation option.
611
614
 
612
- The `loadUtils` option takes a function which returns a Promise which resolves to the utils module. You can `import` the utils module in different ways: (A) from a CDN, (B) from your own hosted version of [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js), or (C) if you use a bundler like Webpack, Vite or Parcel, you can import it directly from the package.
615
+ The `loadUtils` option takes a function that returns a Promise resolving to the utils module. You can `import` the utils module in different ways (shown below): (A) from a CDN, (B) from your own hosted version of [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js), or (C) if you use a bundler like Webpack, Vite or Parcel, you can import it directly from the package.
613
616
 
614
617
  ```js
615
618
  // (A) import utils module from a CDN
616
619
  intlTelInput(htmlInputElement, {
617
- loadUtils: () => import("https://cdn.jsdelivr.net/npm/intl-tel-input@25.10.11/build/js/utils.js"),
620
+ loadUtils: () => import("https://cdn.jsdelivr.net/npm/intl-tel-input@25.11.0/build/js/utils.js"),
618
621
  });
619
622
 
620
623
  // (B) import utils module from your own hosted version of utils.js
621
624
  intlTelInput(htmlInputElement, {
622
- loadUtils: () => import("https://my-domain.com/path/to/utils.js"),
625
+ loadUtils: () => import("/path/to/utils.js"),
623
626
  });
624
627
 
625
- // (C) if your bundler supports it, you can import utils module directly from the package
628
+ // (C) if your bundler supports it, you can import the utils module directly from the package
626
629
  intlTelInput(htmlInputElement, {
627
630
  loadUtils: () => import("intl-tel-input/utils"),
628
631
  });
629
632
  ```
630
633
 
631
- If you want more control over when this file is lazy loaded, you can manually invoke the `attachUtils` static method whenever you like, instead of using the `loadUtils` initialisation option.
634
+ If you want more control over when this file is lazy-loaded, you can manually invoke the `attachUtils` static method whenever you like, instead of using the `loadUtils` initialisation option.
632
635
 
633
636
  ## Troubleshooting
634
637
 
635
638
  **Full-width input**
636
- If you want your input to be full-width, you need to set the container to be the same i.e.
639
+ If you want your input to be full-width, you need to set the container to be the same, i.e.
637
640
 
638
641
  ```css
639
642
  .iti { width: 100%; }
640
643
  ```
641
644
 
642
645
  **dropdownContainer: dropdown not closing on scroll**
643
- If you have a scrolling container other than `window` which is causing problems by not closing the dropdown on scroll, simply listen for the scroll event on that element, and trigger a scroll event on `window`, which in turn will close the dropdown e.g.
646
+ If you have a scrolling container other than `window` which is causing problems by not closing the dropdown on scroll, simply listen for the scroll event on that element, and trigger a scroll event on `window`, which in turn will close the dropdown, e.g.
644
647
 
645
648
  ```js
646
649
  scrollingElement.addEventListener("scroll", () => {
@@ -651,16 +654,16 @@ scrollingElement.addEventListener("scroll", () => {
651
654
  ```
652
655
 
653
656
  **Input margin**
654
- For the sake of alignment, the default CSS forces the input's vertical margin to `0px`. If you want vertical margin, you should add it to the container (with class `iti`).
657
+ For the sake of alignment, the default CSS forces the input's vertical margin to `0px`. If you want a vertical margin, you should add it to the container (with class `iti`).
655
658
 
656
659
  **Displaying error messages**
657
- If your error handling code inserts an error message before the `<input>` it will break the layout. Instead, you must insert it before the container (with class `iti`).
660
+ If your error handling code inserts an error message before the `<input>`, it will break the layout. Instead, you must insert it before the container (with class `iti`).
658
661
 
659
662
  **Dropdown position**
660
663
  The dropdown should automatically appear above/below the input depending on the available space. For this to work properly, you must only initialise the plugin after the `<input>` has been added to the DOM.
661
664
 
662
665
  **Placeholders**
663
- To get the automatic country-specific placeholders, simply omit the placeholder attribute on the `<input>`, or set `autoPlaceholder` to `"aggressive"` to override any existing placeholder,
666
+ To get the automatic country-specific placeholder numbers, simply omit the placeholder attribute on the `<input>`, or set `autoPlaceholder` to `"aggressive"` to override any existing placeholder. Note: this requires the utils script to be loaded.
664
667
 
665
668
  **Bootstrap input groups**
666
669
  A couple of CSS fixes are required to get the plugin to play nice with Bootstrap [input groups](https://getbootstrap.com/docs/3.3/components/#input-groups). You can see a Codepen [here](https://codepen.io/jackocnr/pen/EyPXed).
package/angular/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/angular/demo/validation/validation.component.ts) 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/angularWithUtils"`, to include the utils script. Alternatively, if you use the main `"intl-tel-input/angular"` import, then you should couple this with the `loadUtils` 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 `loadUtils` option to that URL, or alternatively just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@25.10.11/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/angularWithUtils"`, to include the utils script. Alternatively, if you use the main `"intl-tel-input/angular"` import, then you should couple this with the `loadUtils` 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 `loadUtils` option to that URL, or alternatively just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@25.11.0/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 Angular component.