intl-tel-input 17.0.21 → 18.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +19 -15
  2. package/README.md +16 -17
  3. package/build/css/intlTelInput.css +16 -5
  4. package/build/css/intlTelInput.min.css +1 -1
  5. package/build/js/data.js +2 -2
  6. package/build/js/data.min.js +2 -2
  7. package/build/js/intlTelInput-jquery.js +97 -49
  8. package/build/js/intlTelInput-jquery.min.js +3 -3
  9. package/build/js/intlTelInput.js +97 -49
  10. package/build/js/intlTelInput.min.js +3 -3
  11. package/composer.json +1 -1
  12. package/demo.html +5 -5
  13. package/demo_rtl.html +27 -0
  14. package/examples/gen/country-sync.html +6 -6
  15. package/examples/gen/default-country-ip.html +17 -11
  16. package/examples/gen/display-number.html +5 -5
  17. package/examples/gen/hidden-input.html +5 -5
  18. package/examples/gen/init-promise.html +5 -5
  19. package/examples/gen/is-valid-number.html +6 -6
  20. package/examples/gen/js/countrySync.js +1 -1
  21. package/examples/gen/js/defaultCountryIp.js +5 -5
  22. package/examples/gen/js/displayNumber.js +1 -1
  23. package/examples/gen/js/hiddenInput.js +1 -1
  24. package/examples/gen/js/initPromise.js +1 -1
  25. package/examples/gen/js/isValidNumber.js +1 -1
  26. package/examples/gen/js/modifyCountryData.js +1 -1
  27. package/examples/gen/js/multipleInstances.js +2 -2
  28. package/examples/gen/js/nationalMode.js +1 -1
  29. package/examples/gen/js/onlyCountriesEurope.js +1 -1
  30. package/examples/gen/modify-country-data.html +5 -5
  31. package/examples/gen/multiple-instances.html +6 -6
  32. package/examples/gen/national-mode.html +5 -5
  33. package/examples/gen/only-countries-europe.html +7 -7
  34. package/examples/js/defaultCountryIp.js.ejs +4 -4
  35. package/examples/partials/defaultCountryIp.html +4 -1
  36. package/grunt/template.js +1 -1
  37. package/package.json +1 -1
  38. package/spec.html +1 -1
  39. package/src/css/intlTelInput.scss +23 -6
  40. package/src/js/data.js +1 -1
  41. package/src/js/intlTelInput.js +53 -50
  42. package/src/spec/tests/core/dropdownShortcuts.js +3 -2
  43. package/src/spec/tests/core/multipleInstances.js +8 -7
  44. package/src/spec/tests/core/usingDropdown.js +30 -10
  45. package/src/spec/tests/methods/destroy.js +2 -2
  46. package/src/spec/tests/options/allowDropdown.js +8 -0
  47. package/src/spec/tests/options/{autoHideDialCode.js → autoInsertDialCode.js} +18 -28
  48. package/src/spec/tests/options/separateDialCode.js +42 -2
@@ -4,8 +4,8 @@
4
4
  <meta charset="utf-8">
5
5
  <title>Example: Modify country data</title>
6
6
  <link rel="stylesheet" href="../css/prism.css">
7
- <link rel="stylesheet" href="../../build/css/intlTelInput.css?1678446285328">
8
- <link rel="stylesheet" href="../../build/css/demo.css?1678446285328">
7
+ <link rel="stylesheet" href="../../build/css/intlTelInput.css?1680950494824">
8
+ <link rel="stylesheet" href="../../build/css/demo.css?1680950494824">
9
9
 
10
10
 
11
11
  <!-- Global site tag (gtag.js) - Google Analytics -->
@@ -36,7 +36,7 @@ for (var i = 0; i &lt; countryData.length; i++) {
36
36
  }
37
37
 
38
38
  window.intlTelInput(input, {
39
- utilsScript: &quot;../../build/js/utils.js?1678446285328&quot; // just for formatting/placeholders etc
39
+ utilsScript: &quot;../../build/js/utils.js?1680950494824&quot; // just for formatting/placeholders etc
40
40
  });
41
41
  </code></pre>
42
42
 
@@ -46,7 +46,7 @@ window.intlTelInput(input, {
46
46
  </div>
47
47
 
48
48
  <script src="../js/prism.js"></script>
49
- <script src="../../build/js/intlTelInput.js?1678446285328"></script>
50
- <script src="./js/modifyCountryData.js?1678446285328"></script>
49
+ <script src="../../build/js/intlTelInput.js?1680950494824"></script>
50
+ <script src="./js/modifyCountryData.js?1680950494824"></script>
51
51
  </body>
52
52
  </html>
@@ -4,8 +4,8 @@
4
4
  <meta charset="utf-8">
5
5
  <title>Example: Multiple Instances</title>
6
6
  <link rel="stylesheet" href="../css/prism.css">
7
- <link rel="stylesheet" href="../../build/css/intlTelInput.css?1678446285328">
8
- <link rel="stylesheet" href="../../build/css/demo.css?1678446285328">
7
+ <link rel="stylesheet" href="../../build/css/intlTelInput.css?1680950494824">
8
+ <link rel="stylesheet" href="../../build/css/demo.css?1680950494824">
9
9
 
10
10
 
11
11
  <!-- Global site tag (gtag.js) - Google Analytics -->
@@ -36,12 +36,12 @@ var inputMobile = document.querySelector(&quot;#mobile&quot;);
36
36
  window.intlTelInput(inputHome, {
37
37
  initialCountry: &#39;gb&#39;,
38
38
  placeholderNumberType: &#39;FIXED_LINE&#39;,
39
- utilsScript: &quot;../../build/js/utils.js?1678446285328&quot; // just for formatting/placeholders etc
39
+ utilsScript: &quot;../../build/js/utils.js?1680950494824&quot; // just for formatting/placeholders etc
40
40
  });
41
41
  window.intlTelInput(inputMobile, {
42
42
  initialCountry: &#39;gb&#39;,
43
43
  placeholderNumberType: &#39;MOBILE&#39;,
44
- utilsScript: &quot;../../build/js/utils.js?1678446285328&quot;
44
+ utilsScript: &quot;../../build/js/utils.js?1680950494824&quot;
45
45
  });
46
46
  </code></pre>
47
47
 
@@ -54,7 +54,7 @@ Mobile: <input id="mobile" type="tel">
54
54
  </div>
55
55
 
56
56
  <script src="../js/prism.js"></script>
57
- <script src="../../build/js/intlTelInput.js?1678446285328"></script>
58
- <script src="./js/multipleInstances.js?1678446285328"></script>
57
+ <script src="../../build/js/intlTelInput.js?1680950494824"></script>
58
+ <script src="./js/multipleInstances.js?1680950494824"></script>
59
59
  </body>
60
60
  </html>
@@ -4,8 +4,8 @@
4
4
  <meta charset="utf-8">
5
5
  <title>Example: National Mode</title>
6
6
  <link rel="stylesheet" href="../css/prism.css">
7
- <link rel="stylesheet" href="../../build/css/intlTelInput.css?1678446285328">
8
- <link rel="stylesheet" href="../../build/css/demo.css?1678446285328">
7
+ <link rel="stylesheet" href="../../build/css/intlTelInput.css?1680950494824">
8
+ <link rel="stylesheet" href="../../build/css/demo.css?1680950494824">
9
9
 
10
10
 
11
11
  <!-- Global site tag (gtag.js) - Google Analytics -->
@@ -34,7 +34,7 @@
34
34
 
35
35
  var iti = window.intlTelInput(input, {
36
36
  nationalMode: true,
37
- utilsScript: &quot;../../build/js/utils.js?1678446285328&quot; // just for formatting/placeholders etc
37
+ utilsScript: &quot;../../build/js/utils.js?1680950494824&quot; // just for formatting/placeholders etc
38
38
  });
39
39
 
40
40
  var handleChange = function() {
@@ -57,7 +57,7 @@ input.addEventListener(&#39;keyup&#39;, handleChange);
57
57
  </div>
58
58
 
59
59
  <script src="../js/prism.js"></script>
60
- <script src="../../build/js/intlTelInput.js?1678446285328"></script>
61
- <script src="./js/nationalMode.js?1678446285328"></script>
60
+ <script src="../../build/js/intlTelInput.js?1680950494824"></script>
61
+ <script src="./js/nationalMode.js?1680950494824"></script>
62
62
  </body>
63
63
  </html>
@@ -2,10 +2,10 @@
2
2
  <html>
3
3
  <head>
4
4
  <meta charset="utf-8">
5
- <title>Example: European countries</title>
5
+ <title>Example: Only countries option</title>
6
6
  <link rel="stylesheet" href="../css/prism.css">
7
- <link rel="stylesheet" href="../../build/css/intlTelInput.css?1678446285328">
8
- <link rel="stylesheet" href="../../build/css/demo.css?1678446285328">
7
+ <link rel="stylesheet" href="../../build/css/intlTelInput.css?1680950494824">
8
+ <link rel="stylesheet" href="../../build/css/demo.css?1680950494824">
9
9
 
10
10
 
11
11
  <!-- Global site tag (gtag.js) - Google Analytics -->
@@ -20,7 +20,7 @@
20
20
 
21
21
  <body>
22
22
  <a href="/">Back</a>
23
- <h1>Example: European countries</h1>
23
+ <h1>Example: Only countries option</h1>
24
24
  <p>Set onlyCountries option to just European country codes.</p>
25
25
 
26
26
  <h2>Markup</h2>
@@ -33,7 +33,7 @@ window.intlTelInput(input, {
33
33
  &quot;ee&quot;, &quot;fo&quot;, &quot;fi&quot;, &quot;fr&quot;, &quot;de&quot;, &quot;gi&quot;, &quot;gr&quot;, &quot;va&quot;, &quot;hu&quot;, &quot;is&quot;, &quot;ie&quot;, &quot;it&quot;, &quot;lv&quot;,
34
34
  &quot;li&quot;, &quot;lt&quot;, &quot;lu&quot;, &quot;mk&quot;, &quot;mt&quot;, &quot;md&quot;, &quot;mc&quot;, &quot;me&quot;, &quot;nl&quot;, &quot;no&quot;, &quot;pl&quot;, &quot;pt&quot;, &quot;ro&quot;,
35
35
  &quot;ru&quot;, &quot;sm&quot;, &quot;rs&quot;, &quot;sk&quot;, &quot;si&quot;, &quot;es&quot;, &quot;se&quot;, &quot;ch&quot;, &quot;ua&quot;, &quot;gb&quot;],
36
- utilsScript: &quot;../../build/js/utils.js?1678446285328&quot; // just for formatting/placeholders etc
36
+ utilsScript: &quot;../../build/js/utils.js?1680950494824&quot; // just for formatting/placeholders etc
37
37
  });
38
38
  </code></pre>
39
39
 
@@ -43,7 +43,7 @@ window.intlTelInput(input, {
43
43
  </div>
44
44
 
45
45
  <script src="../js/prism.js"></script>
46
- <script src="../../build/js/intlTelInput.js?1678446285328"></script>
47
- <script src="./js/onlyCountriesEurope.js?1678446285328"></script>
46
+ <script src="../../build/js/intlTelInput.js?1680950494824"></script>
47
+ <script src="./js/onlyCountriesEurope.js?1680950494824"></script>
48
48
  </body>
49
49
  </html>
@@ -2,10 +2,10 @@ var input = document.querySelector("#phone");
2
2
  window.intlTelInput(input, {
3
3
  initialCountry: "auto",
4
4
  geoIpLookup: function(callback) {
5
- $.get('https://ipinfo.io', function() {}, "jsonp").always(function(resp) {
6
- var countryCode = (resp && resp.country) ? resp.country : "us";
7
- callback(countryCode);
8
- });
5
+ fetch("http://ip-api.com/json")
6
+ .then(function(res) { return res.json(); })
7
+ .then(function(data) { callback(data.countryCode); })
8
+ .catch(function() { callback("us"); });
9
9
  },
10
10
  utilsScript: "../../build/js/utils.js?<%= time %>" // just for formatting/placeholders etc
11
11
  });
@@ -1,2 +1,5 @@
1
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
1
+ <!-- fetch and Promise polyfills for IE11 -->
2
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/3.6.2/fetch.min.js"></script>
3
+ <script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"></script>
4
+
2
5
  <input id="phone" type="tel">
package/grunt/template.js CHANGED
@@ -169,7 +169,7 @@ module.exports = function(grunt) {
169
169
  data: function() {
170
170
  return {
171
171
  time: time,
172
- title: "European countries",
172
+ title: "Only countries option",
173
173
  desc: "Set onlyCountries option to just European country codes.",
174
174
  stylesheet: "",
175
175
  markup: grunt.file.read('examples/partials/simpleInput.html'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intl-tel-input",
3
- "version": "17.0.21",
3
+ "version": "18.0.1",
4
4
  "description": "A JavaScript plugin for entering and validating international telephone numbers",
5
5
  "keywords": [
6
6
  "international",
package/spec.html CHANGED
@@ -70,7 +70,7 @@
70
70
 
71
71
  <script src="src/spec/tests/options/allowDropdown.js"></script>
72
72
 
73
- <script src="src/spec/tests/options/autoHideDialCode.js"></script>
73
+ <script src="src/spec/tests/options/autoInsertDialCode.js"></script>
74
74
 
75
75
  <script src="src/spec/tests/options/autoPlaceholder.js"></script>
76
76
 
@@ -44,7 +44,6 @@ $mobilePopupMargin: 30px !default;
44
44
  // http://www.paulirish.com/2012/box-sizing-border-box-ftw/
45
45
  * {
46
46
  box-sizing: border-box;
47
- -moz-box-sizing: border-box;
48
47
  }
49
48
 
50
49
  &__hide {
@@ -111,6 +110,11 @@ $mobilePopupMargin: 30px !default;
111
110
  border-right: $triangleBorder solid transparent;
112
111
  border-top: $arrowHeight solid $arrowColor;
113
112
 
113
+ [dir=rtl] & {
114
+ margin-right: $arrowPadding;
115
+ margin-left: 0;
116
+ }
117
+
114
118
  &--up {
115
119
  border-top: none;
116
120
  border-bottom: $arrowHeight solid $arrowColor;
@@ -125,8 +129,6 @@ $mobilePopupMargin: 30px !default;
125
129
 
126
130
  // override default list styles
127
131
  list-style: none;
128
- // in case any container has text-align:center
129
- text-align: left;
130
132
 
131
133
  // place menu above the input element
132
134
  &--dropup {
@@ -175,6 +177,8 @@ $mobilePopupMargin: 30px !default;
175
177
  // each country item in dropdown (we must have separate class to differentiate from dividers)
176
178
  &__country {
177
179
  // Note: decided not to use line-height here for alignment because it causes issues e.g. large font-sizes will overlap, and also looks bad if one country overflows onto 2 lines
180
+ display: flex;
181
+ align-items: center;
178
182
  padding: 5px 10px;
179
183
  outline: none;
180
184
  }
@@ -188,11 +192,13 @@ $mobilePopupMargin: 30px !default;
188
192
  }
189
193
 
190
194
  // spacing between country flag, name and dial code
191
- &__flag-box, &__country-name, &__dial-code {
192
- vertical-align: middle;
193
- }
194
195
  &__flag-box, &__country-name {
195
196
  margin-right: 6px;
197
+
198
+ [dir=rtl] & {
199
+ margin-right: 0;
200
+ margin-left: 6px;
201
+ }
196
202
  }
197
203
 
198
204
  // these settings are independent of each other, but both move selected flag to left of input
@@ -201,10 +207,21 @@ $mobilePopupMargin: 30px !default;
201
207
  padding-right: $inputPadding;
202
208
  padding-left: $selectedFlagArrowWidth + $inputPadding;
203
209
  margin-left: 0;
210
+
211
+ [dir=rtl] & {
212
+ padding-right: $selectedFlagArrowWidth + $inputPadding;
213
+ padding-left: $inputPadding;
214
+ margin-right: 0;
215
+ }
204
216
  }
205
217
  .iti__flag-container {
206
218
  right: auto;
207
219
  left: 0;
220
+
221
+ [dir=rtl] & {
222
+ right: 0;
223
+ left: auto;
224
+ }
208
225
  }
209
226
  }
210
227
 
package/src/js/data.js CHANGED
@@ -220,7 +220,7 @@ var allCountries = [
220
220
  "ca",
221
221
  "1",
222
222
  1,
223
- ["204", "226", "236", "249", "250", "289", "306", "343", "365", "387", "403", "416", "418", "431", "437", "438", "450", "506", "514", "519", "548", "579", "581", "587", "604", "613", "639", "647", "672", "705", "709", "742", "778", "780", "782", "807", "819", "825", "867", "873", "902", "905"]
223
+ ["204", "226", "236", "249", "250", "289", "306", "343", "365", "367", "368", "387", "403", "416", "418", "431", "437", "438", "450", "474", "506", "514", "519", "548", "579", "581", "584", "587", "604", "613", "639", "647", "672", "705", "709", "742", "778", "780", "782", "807", "819", "825", "867", "873", "902", "905"]
224
224
  ],
225
225
  [
226
226
  "Cape Verde (Kabu Verdi)",
@@ -15,8 +15,9 @@ let id = 0;
15
15
  const defaults = {
16
16
  // whether or not to allow the dropdown
17
17
  allowDropdown: true,
18
- // if there is just a dial code in the input: remove it on blur
19
- autoHideDialCode: true,
18
+ // auto insert dial code (A) on init, (B) on user selecting a country, (C) on calling setCountry
19
+ // also listen for blur/submit and auto remove dial code if that's all there is
20
+ autoInsertDialCode: false,
20
21
  // add a placeholder in the input with an example number for the selected country
21
22
  autoPlaceholder: 'polite',
22
23
  // modify the parentClass
@@ -37,7 +38,7 @@ const defaults = {
37
38
  initialCountry: '',
38
39
  // localized country names e.g. { 'de': 'Deutschland' }
39
40
  localizedCountries: null,
40
- // don't insert international dial codes
41
+ // deal with national numbers instead of international numbers
41
42
  nationalMode: true,
42
43
  // display only these countries
43
44
  onlyCountries: [],
@@ -45,7 +46,7 @@ const defaults = {
45
46
  placeholderNumberType: 'MOBILE',
46
47
  // the countries at the top of the list. defaults to united states and united kingdom
47
48
  preferredCountries: ['us', 'gb'],
48
- // display the country dial code next to the selected flag so it's not part of the typed number
49
+ // display the country dial code next to the selected flag
49
50
  separateDialCode: false,
50
51
  // specify the path to the libphonenumber script to enable validation/formatting
51
52
  utilsScript: '',
@@ -94,15 +95,11 @@ class Iti {
94
95
  }
95
96
 
96
97
  _init() {
97
- // if in nationalMode, disable options relating to dial codes
98
- if (this.options.nationalMode) this.options.autoHideDialCode = false;
98
+ // if in nationalMode, do not insert dial codes
99
+ if (this.options.nationalMode) this.options.autoInsertDialCode = false;
99
100
 
100
- // if separateDialCode then doesn't make sense to A) insert dial code into input
101
- // (autoHideDialCode), and B) display national numbers (because we're displaying the country
102
- // dial code next to them)
103
- if (this.options.separateDialCode) {
104
- this.options.autoHideDialCode = this.options.nationalMode = false;
105
- }
101
+ // if separateDialCode enabled, do not insert dial codes
102
+ if (this.options.separateDialCode) this.options.autoInsertDialCode = false;
106
103
 
107
104
  // we cannot just test screen size as some smartphones/website meta tags will report desktop
108
105
  // resolutions
@@ -151,7 +148,7 @@ class Iti {
151
148
  // set the initial state of the input value and the selected flag
152
149
  this._setInitialState();
153
150
 
154
- // start all of the event listeners: autoHideDialCode, input keydown, selectedFlag click
151
+ // start all of the event listeners: autoInsertDialCode, input keydown, selectedFlag click
155
152
  this._initListeners();
156
153
 
157
154
  // utils script, and auto country
@@ -237,7 +234,9 @@ class Iti {
237
234
 
238
235
  // sort by country name
239
236
  _countryNameSort(a, b) {
240
- return a.name.localeCompare(b.name);
237
+ if (a.name < b.name) return -1;
238
+ if (a.name > b.name) return 1;
239
+ return 0;
241
240
  }
242
241
 
243
242
 
@@ -329,22 +328,35 @@ class Iti {
329
328
  wrapper.appendChild(this.telInput);
330
329
 
331
330
  // selected flag (displayed to left of input)
331
+ // using Aria tags for "Select-Only Combobox Example"
332
+ // https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/
332
333
  this.selectedFlag = this._createEl('div', {
333
334
  class: 'iti__selected-flag',
334
- role: 'combobox',
335
- 'aria-controls': `iti-${this.id}__country-listbox`,
336
- 'aria-owns': `iti-${this.id}__country-listbox`,
337
- 'aria-expanded': 'false',
335
+ ...(this.options.allowDropdown && {
336
+ role: 'combobox',
337
+ 'aria-haspopup': 'listbox',
338
+ 'aria-controls': `iti-${this.id}__country-listbox`,
339
+ 'aria-owns': `iti-${this.id}__country-listbox`,
340
+ 'aria-expanded': 'false',
341
+ 'aria-label': 'Telephone country code',
342
+ }),
338
343
  }, this.flagsContainer);
339
344
  this.selectedFlagInner = this._createEl('div', { class: 'iti__flag' }, this.selectedFlag);
340
345
 
346
+ if (this.telInput.disabled) {
347
+ this.selectedFlag.setAttribute('aria-disabled', 'true');
348
+ }
349
+
341
350
  if (this.options.separateDialCode) {
342
351
  this.selectedDialCode = this._createEl('div', { class: 'iti__selected-dial-code' }, this.selectedFlag);
343
352
  }
344
353
 
345
354
  if (this.options.allowDropdown) {
346
- // make element focusable and tab navigable
347
- this.selectedFlag.setAttribute('tabindex', '0');
355
+ if (!this.telInput.disabled) {
356
+ // make element focusable and tab navigable
357
+ this.selectedFlag.setAttribute('tabindex', '0');
358
+ }
359
+
348
360
  this.dropdownArrow = this._createEl('div', { class: 'iti__arrow' }, this.selectedFlag);
349
361
 
350
362
  // country dropdown: preferred countries, then divider, then all countries
@@ -431,9 +443,7 @@ class Iti {
431
443
  const isRegionlessNanp = this._isRegionlessNanp(val);
432
444
  const {
433
445
  initialCountry,
434
- nationalMode,
435
- autoHideDialCode,
436
- separateDialCode,
446
+ autoInsertDialCode,
437
447
  } = this.options;
438
448
 
439
449
  // if we already have a dial code, and it's not a regionlessNanp, we can go ahead and set the
@@ -458,8 +468,8 @@ class Iti {
458
468
  }
459
469
  }
460
470
 
461
- // if empty and no nationalMode and no autoHideDialCode then insert the default dial code
462
- if (!val && !nationalMode && !autoHideDialCode && !separateDialCode) {
471
+ // if empty and autoInsertDialCode then insert the dial code
472
+ if (!val && autoInsertDialCode) {
463
473
  this.telInput.value = `+${this.selectedCountryData.dialCode}`;
464
474
  }
465
475
  }
@@ -473,7 +483,7 @@ class Iti {
473
483
  // initialise the main event listeners: input keyup, and click selected flag
474
484
  _initListeners() {
475
485
  this._initKeyListeners();
476
- if (this.options.autoHideDialCode) this._initBlurListeners();
486
+ if (this.options.autoInsertDialCode) this._initBlurListeners();
477
487
  if (this.options.allowDropdown) this._initDropdownListeners();
478
488
  if (this.hiddenInput) this._initHiddenInputListener();
479
489
  }
@@ -614,7 +624,7 @@ class Iti {
614
624
  }
615
625
 
616
626
 
617
- // listen for blur/submit (for autoHideDialCode feature)
627
+ // listen for blur/submit (for autoInsertDialCode feature)
618
628
  _initBlurListeners() {
619
629
  // on blur or form submit: if just a dial code then remove it
620
630
  this._handleSubmitOrBlurEvent = () => {
@@ -840,8 +850,7 @@ class Iti {
840
850
  _updateValFromNumber(originalNumber) {
841
851
  let number = originalNumber;
842
852
  if (this.options.formatOnDisplay && window.intlTelInputUtils && this.selectedCountryData) {
843
- const useNational = (!this.options.separateDialCode
844
- && (this.options.nationalMode || number.charAt(0) !== '+'));
853
+ const useNational = (this.options.nationalMode || (number.charAt(0) !== '+' && !this.options.separateDialCode));
845
854
  const { NATIONAL, INTERNATIONAL } = intlTelInputUtils.numberFormat;
846
855
  const format = useNational ? NATIONAL : INTERNATIONAL;
847
856
  number = intlTelInputUtils.formatNumber(number, this.selectedCountryData.iso2, format);
@@ -862,13 +871,13 @@ class Iti {
862
871
  // dial code, so fine to ignore this bit
863
872
  let number = originalNumber;
864
873
  const selectedDialCode = this.selectedCountryData.dialCode;
865
- const isNanp = selectedDialCode === '1';
874
+ const isNanp = (selectedDialCode === '1');
866
875
  if (number && this.options.nationalMode && isNanp && number.charAt(0) !== '+') {
867
876
  if (number.charAt(0) !== '1') number = `1${number}`;
868
877
  number = `+${number}`;
869
878
  }
870
879
 
871
- // update flag if user types area code for another country
880
+ // if separateDialCode enabled, then consider the selected dial code to be part of the number
872
881
  if (this.options.separateDialCode && selectedDialCode && number.charAt(0) !== '+') {
873
882
  number = `+${selectedDialCode}${number}`;
874
883
  }
@@ -936,6 +945,7 @@ class Iti {
936
945
  if (prevItem) prevItem.classList.remove('iti__highlight');
937
946
  this.highlightedItem = listItem;
938
947
  this.highlightedItem.classList.add('iti__highlight');
948
+ this.selectedFlag.setAttribute('aria-activedescendant', listItem.getAttribute('id'));
939
949
 
940
950
  if (shouldFocus) this.highlightedItem.focus();
941
951
  }
@@ -975,7 +985,7 @@ class Iti {
975
985
  this.selectedFlag.setAttribute('title', title);
976
986
 
977
987
  if (this.options.separateDialCode) {
978
- const dialCode = (this.selectedCountryData.dialCode) ? `+${this.selectedCountryData.dialCode}` : '';
988
+ const dialCode = this.selectedCountryData.dialCode ? `+${this.selectedCountryData.dialCode}` : '';
979
989
  this.selectedDialCode.innerHTML = dialCode;
980
990
  // offsetWidth is zero if input is in a hidden container during initialisation
981
991
  const selectedFlagWidth = this.selectedFlag.offsetWidth || this._getHiddenSelectedFlagWidth();
@@ -1000,7 +1010,6 @@ class Iti {
1000
1010
  nextItem.setAttribute('aria-selected', 'true');
1001
1011
  nextItem.classList.add('iti__active');
1002
1012
  this.activeItem = nextItem;
1003
- this.selectedFlag.setAttribute('aria-activedescendant', nextItem.getAttribute('id'));
1004
1013
  }
1005
1014
  }
1006
1015
 
@@ -1052,7 +1061,7 @@ class Iti {
1052
1061
  const flagChanged = this._setFlag(listItem.getAttribute('data-country-code'));
1053
1062
  this._closeDropdown();
1054
1063
 
1055
- this._updateDialCode(listItem.getAttribute('data-dial-code'), true);
1064
+ this._updateDialCode(listItem.getAttribute('data-dial-code'));
1056
1065
 
1057
1066
  // focus the input
1058
1067
  this.telInput.focus();
@@ -1071,6 +1080,8 @@ class Iti {
1071
1080
  _closeDropdown() {
1072
1081
  this.countryList.classList.add('iti__hide');
1073
1082
  this.selectedFlag.setAttribute('aria-expanded', 'false');
1083
+ this.selectedFlag.removeAttribute('aria-activedescendant');
1084
+
1074
1085
  // update the arrow
1075
1086
  this.dropdownArrow.classList.remove('iti__arrow--up');
1076
1087
 
@@ -1119,7 +1130,7 @@ class Iti {
1119
1130
 
1120
1131
  // replace any existing dial code with the new one
1121
1132
  // Note: called from _selectListItem and setCountry
1122
- _updateDialCode(newDialCodeBare, hasSelectedListItem) {
1133
+ _updateDialCode(newDialCodeBare) {
1123
1134
  const inputVal = this.telInput.value;
1124
1135
  // save having to pass this every time
1125
1136
  const newDialCode = `+${newDialCodeBare}`;
@@ -1136,24 +1147,16 @@ class Iti {
1136
1147
  // (no way to determine where the invalid dial code ends and the rest of the number begins)
1137
1148
  newNumber = newDialCode;
1138
1149
  }
1139
- } else if (this.options.nationalMode || this.options.separateDialCode) {
1140
- // don't do anything
1141
- return;
1142
- } else {
1143
- // nationalMode is disabled
1150
+ this.telInput.value = newNumber;
1151
+ } else if (this.options.autoInsertDialCode) {
1144
1152
  if (inputVal) {
1145
1153
  // there is an existing value with no dial code: prefix the new dial code
1146
1154
  newNumber = newDialCode + inputVal;
1147
- } else if (hasSelectedListItem || !this.options.autoHideDialCode) {
1148
- // no existing value and either they've just selected a list item, or autoHideDialCode is
1149
- // disabled: insert new dial code
1150
- newNumber = newDialCode;
1151
1155
  } else {
1152
- return;
1156
+ newNumber = newDialCode;
1153
1157
  }
1158
+ this.telInput.value = newNumber;
1154
1159
  }
1155
-
1156
- this.telInput.value = newNumber;
1157
1160
  }
1158
1161
 
1159
1162
 
@@ -1296,8 +1299,8 @@ class Iti {
1296
1299
  // unbind hiddenInput listeners
1297
1300
  if (this.hiddenInput && form) form.removeEventListener('submit', this._handleHiddenInputSubmit);
1298
1301
 
1299
- // unbind autoHideDialCode listeners
1300
- if (this.options.autoHideDialCode) {
1302
+ // unbind autoInsertDialCode listeners
1303
+ if (this.options.autoInsertDialCode) {
1301
1304
  if (form) form.removeEventListener('submit', this._handleSubmitOrBlurEvent);
1302
1305
  this.telInput.removeEventListener('blur', this._handleSubmitOrBlurEvent);
1303
1306
  }
@@ -1377,7 +1380,7 @@ class Iti {
1377
1380
  // check if already selected
1378
1381
  if (!this.selectedFlagInner.classList.contains(`iti__${countryCode}`)) {
1379
1382
  this._setFlag(countryCode);
1380
- this._updateDialCode(this.selectedCountryData.dialCode, false);
1383
+ this._updateDialCode(this.selectedCountryData.dialCode);
1381
1384
  this._triggerCountryChange();
1382
1385
  }
1383
1386
  }
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
 
3
- describe("dropdown shortcuts: init plugin (with nationalMode=false) to test keyboard shortcuts", function() {
3
+ describe("dropdown shortcuts: init plugin (with nationalMode=false, autoInsertDialCode=true) to test keyboard shortcuts", function() {
4
4
 
5
5
  beforeEach(function() {
6
6
  intlSetup();
7
7
  input = $("<input>").appendTo("body");
8
8
  iti = window.intlTelInput(input[0], {
9
- nationalMode: false
9
+ nationalMode: false,
10
+ autoInsertDialCode: true,
10
11
  });
11
12
  });
12
13
 
@@ -7,20 +7,21 @@ describe("multiple instances: init plugin (with nationalMode=false) to test mult
7
7
  afghanistanCountryCode = "af",
8
8
  albaniaCountryCode = "al",
9
9
  chinaCountryCode = "cn",
10
- chinaDialCode = "+86";
10
+ chinaDialCode = "+86",
11
+ koreaCountryCode = 'kr',
12
+ russiaCountryCode = 'ru';
11
13
 
12
14
  beforeEach(function() {
13
15
  intlSetup();
14
16
  input = $("<input>").wrap("div");
15
17
  input2 = $("<input>").wrap("div");
16
- // japan and china
18
+
17
19
  iti = window.intlTelInput(input[0], {
18
- onlyCountries: [chinaCountryCode, afghanistanCountryCode],
20
+ onlyCountries: [afghanistanCountryCode, chinaCountryCode],
19
21
  nationalMode: false,
20
22
  });
21
- // korea, china and russia
22
23
  iti2 = window.intlTelInput(input2[0], {
23
- onlyCountries: ['kr', chinaCountryCode, 'ru', albaniaCountryCode],
24
+ onlyCountries: [albaniaCountryCode, chinaCountryCode, koreaCountryCode, russiaCountryCode],
24
25
  nationalMode: false,
25
26
  });
26
27
  $("body").append(getParentElement(input)).append(getParentElement(input2));
@@ -45,8 +46,8 @@ describe("multiple instances: init plugin (with nationalMode=false) to test mult
45
46
 
46
47
  it("selecting an item from the first input dropdown only updates the flag on that input", function() {
47
48
  selectFlag(chinaCountryCode);
48
- expect(getInputVal()).toEqual(chinaDialCode);
49
- expect(getInputVal(input2)).toEqual("");
49
+ expect(getSelectedFlagElement()).toHaveClass(`iti__${chinaCountryCode}`);
50
+ expect(getSelectedFlagElement(input2)).toHaveClass(`iti__${albaniaCountryCode}`);
50
51
  });
51
52
 
52
53
  it("updating the number on the first input only updates the flag on that input", function() {