intl-tel-input 17.0.21 → 18.0.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 +19 -15
- package/README.md +14 -14
- package/build/css/intlTelInput.css +16 -5
- package/build/css/intlTelInput.min.css +1 -1
- package/build/js/data.js +2 -2
- package/build/js/data.min.js +2 -2
- package/build/js/intlTelInput-jquery.js +97 -49
- package/build/js/intlTelInput-jquery.min.js +3 -3
- package/build/js/intlTelInput.js +97 -49
- package/build/js/intlTelInput.min.js +3 -3
- package/composer.json +1 -1
- package/demo.html +6 -6
- package/demo_rtl.html +47 -0
- package/examples/gen/country-sync.html +6 -6
- package/examples/gen/default-country-ip.html +5 -5
- package/examples/gen/display-number.html +5 -5
- package/examples/gen/hidden-input.html +5 -5
- package/examples/gen/init-promise.html +5 -5
- package/examples/gen/is-valid-number.html +6 -6
- package/examples/gen/js/countrySync.js +1 -1
- package/examples/gen/js/defaultCountryIp.js +1 -1
- package/examples/gen/js/displayNumber.js +1 -1
- package/examples/gen/js/hiddenInput.js +1 -1
- package/examples/gen/js/initPromise.js +1 -1
- package/examples/gen/js/isValidNumber.js +1 -1
- package/examples/gen/js/modifyCountryData.js +1 -1
- package/examples/gen/js/multipleInstances.js +2 -2
- package/examples/gen/js/nationalMode.js +1 -1
- package/examples/gen/js/onlyCountriesEurope.js +1 -1
- package/examples/gen/modify-country-data.html +5 -5
- package/examples/gen/multiple-instances.html +6 -6
- package/examples/gen/national-mode.html +5 -5
- package/examples/gen/only-countries-europe.html +5 -5
- package/package.json +1 -1
- package/spec.html +1 -1
- package/src/css/intlTelInput.scss +23 -6
- package/src/js/data.js +1 -1
- package/src/js/intlTelInput.js +53 -50
- package/src/spec/tests/core/dropdownShortcuts.js +3 -2
- package/src/spec/tests/core/multipleInstances.js +8 -7
- package/src/spec/tests/core/usingDropdown.js +30 -10
- package/src/spec/tests/methods/destroy.js +2 -2
- package/src/spec/tests/options/allowDropdown.js +8 -0
- package/src/spec/tests/options/{autoHideDialCode.js → autoInsertDialCode.js} +18 -28
- package/src/spec/tests/options/separateDialCode.js +42 -2
|
@@ -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?
|
|
8
|
-
<link rel="stylesheet" href="../../build/css/demo.css?
|
|
7
|
+
<link rel="stylesheet" href="../../build/css/intlTelInput.css?1680898893466">
|
|
8
|
+
<link rel="stylesheet" href="../../build/css/demo.css?1680898893466">
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
<!-- Global site tag (gtag.js) - Google Analytics -->
|
|
@@ -36,12 +36,12 @@ var inputMobile = document.querySelector("#mobile");
|
|
|
36
36
|
window.intlTelInput(inputHome, {
|
|
37
37
|
initialCountry: 'gb',
|
|
38
38
|
placeholderNumberType: 'FIXED_LINE',
|
|
39
|
-
utilsScript: "../../build/js/utils.js?
|
|
39
|
+
utilsScript: "../../build/js/utils.js?1680898893466" // just for formatting/placeholders etc
|
|
40
40
|
});
|
|
41
41
|
window.intlTelInput(inputMobile, {
|
|
42
42
|
initialCountry: 'gb',
|
|
43
43
|
placeholderNumberType: 'MOBILE',
|
|
44
|
-
utilsScript: "../../build/js/utils.js?
|
|
44
|
+
utilsScript: "../../build/js/utils.js?1680898893466"
|
|
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?
|
|
58
|
-
<script src="./js/multipleInstances.js?
|
|
57
|
+
<script src="../../build/js/intlTelInput.js?1680898893466"></script>
|
|
58
|
+
<script src="./js/multipleInstances.js?1680898893466"></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?
|
|
8
|
-
<link rel="stylesheet" href="../../build/css/demo.css?
|
|
7
|
+
<link rel="stylesheet" href="../../build/css/intlTelInput.css?1680898893466">
|
|
8
|
+
<link rel="stylesheet" href="../../build/css/demo.css?1680898893466">
|
|
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: "../../build/js/utils.js?
|
|
37
|
+
utilsScript: "../../build/js/utils.js?1680898893466" // just for formatting/placeholders etc
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
var handleChange = function() {
|
|
@@ -57,7 +57,7 @@ input.addEventListener('keyup', handleChange);
|
|
|
57
57
|
</div>
|
|
58
58
|
|
|
59
59
|
<script src="../js/prism.js"></script>
|
|
60
|
-
<script src="../../build/js/intlTelInput.js?
|
|
61
|
-
<script src="./js/nationalMode.js?
|
|
60
|
+
<script src="../../build/js/intlTelInput.js?1680898893466"></script>
|
|
61
|
+
<script src="./js/nationalMode.js?1680898893466"></script>
|
|
62
62
|
</body>
|
|
63
63
|
</html>
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<title>Example: European countries</title>
|
|
6
6
|
<link rel="stylesheet" href="../css/prism.css">
|
|
7
|
-
<link rel="stylesheet" href="../../build/css/intlTelInput.css?
|
|
8
|
-
<link rel="stylesheet" href="../../build/css/demo.css?
|
|
7
|
+
<link rel="stylesheet" href="../../build/css/intlTelInput.css?1680898893466">
|
|
8
|
+
<link rel="stylesheet" href="../../build/css/demo.css?1680898893466">
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
<!-- Global site tag (gtag.js) - Google Analytics -->
|
|
@@ -33,7 +33,7 @@ window.intlTelInput(input, {
|
|
|
33
33
|
"ee", "fo", "fi", "fr", "de", "gi", "gr", "va", "hu", "is", "ie", "it", "lv",
|
|
34
34
|
"li", "lt", "lu", "mk", "mt", "md", "mc", "me", "nl", "no", "pl", "pt", "ro",
|
|
35
35
|
"ru", "sm", "rs", "sk", "si", "es", "se", "ch", "ua", "gb"],
|
|
36
|
-
utilsScript: "../../build/js/utils.js?
|
|
36
|
+
utilsScript: "../../build/js/utils.js?1680898893466" // 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?
|
|
47
|
-
<script src="./js/onlyCountriesEurope.js?
|
|
46
|
+
<script src="../../build/js/intlTelInput.js?1680898893466"></script>
|
|
47
|
+
<script src="./js/onlyCountriesEurope.js?1680898893466"></script>
|
|
48
48
|
</body>
|
|
49
49
|
</html>
|
package/package.json
CHANGED
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/
|
|
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)",
|
package/src/js/intlTelInput.js
CHANGED
|
@@ -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
|
-
//
|
|
19
|
-
|
|
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
|
-
//
|
|
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
|
|
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,
|
|
98
|
-
if (this.options.nationalMode) this.options.
|
|
98
|
+
// if in nationalMode, do not insert dial codes
|
|
99
|
+
if (this.options.nationalMode) this.options.autoInsertDialCode = false;
|
|
99
100
|
|
|
100
|
-
// if separateDialCode
|
|
101
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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
|
-
|
|
347
|
-
|
|
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
|
-
|
|
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
|
|
462
|
-
if (!val &&
|
|
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.
|
|
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
|
|
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
|
-
//
|
|
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 =
|
|
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')
|
|
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
|
|
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
|
-
|
|
1140
|
-
|
|
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
|
-
|
|
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
|
|
1300
|
-
if (this.options.
|
|
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
|
|
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
|
-
|
|
18
|
+
|
|
17
19
|
iti = window.intlTelInput(input[0], {
|
|
18
|
-
onlyCountries: [
|
|
20
|
+
onlyCountries: [afghanistanCountryCode, chinaCountryCode],
|
|
19
21
|
nationalMode: false,
|
|
20
22
|
});
|
|
21
|
-
// korea, china and russia
|
|
22
23
|
iti2 = window.intlTelInput(input2[0], {
|
|
23
|
-
onlyCountries: [
|
|
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(
|
|
49
|
-
expect(
|
|
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() {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
describe("using dropdown: init plugin with nationalMode=false", function() {
|
|
3
|
+
describe("using dropdown: init plugin on normal input with nationalMode=false, autoInsertDialCode=true", function() {
|
|
4
4
|
|
|
5
5
|
beforeEach(function() {
|
|
6
6
|
intlSetup();
|
|
7
7
|
input = $("<input>").appendTo("body");
|
|
8
|
-
// nationalMode=false because we're playing with dial codes
|
|
8
|
+
// nationalMode=false and autoInsertDialCode=true because we're playing with dial codes
|
|
9
9
|
iti = window.intlTelInput(input[0], {
|
|
10
|
-
nationalMode: false
|
|
10
|
+
nationalMode: false,
|
|
11
|
+
autoInsertDialCode: true,
|
|
11
12
|
});
|
|
12
13
|
});
|
|
13
14
|
|
|
@@ -15,19 +16,16 @@ describe("using dropdown: init plugin with nationalMode=false", function() {
|
|
|
15
16
|
intlTeardown();
|
|
16
17
|
});
|
|
17
18
|
|
|
18
|
-
it("
|
|
19
|
+
it("clicking the selected flag opens the dropdown", function() {
|
|
19
20
|
getSelectedFlagContainer()[0].click();
|
|
20
21
|
expect(getListElement()).toBeVisible();
|
|
21
22
|
});
|
|
22
23
|
|
|
23
|
-
it("
|
|
24
|
-
|
|
25
|
-
getSelectedFlagContainer()
|
|
26
|
-
expect(getListElement()).not.toBeVisible();
|
|
24
|
+
it("allows focusing the dropdown using the keyboard", function() {
|
|
25
|
+
expect(getSelectedFlagContainer().attr('tabindex')).toEqual('0');
|
|
26
|
+
expect(getSelectedFlagContainer()).not.toHaveAttr('aria-disabled');
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
29
|
describe("clicking the selected flag to open the dropdown", function() {
|
|
32
30
|
|
|
33
31
|
beforeEach(function() {
|
|
@@ -79,3 +77,25 @@ describe("using dropdown: init plugin with nationalMode=false", function() {
|
|
|
79
77
|
});
|
|
80
78
|
|
|
81
79
|
});
|
|
80
|
+
|
|
81
|
+
describe("using dropdown: disabled input", () => {
|
|
82
|
+
beforeEach(function() {
|
|
83
|
+
intlSetup();
|
|
84
|
+
input = $("<input disabled>").appendTo("body");
|
|
85
|
+
iti = window.intlTelInput(input[0]);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
afterEach(function() {
|
|
89
|
+
intlTeardown();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("prevents the user from opening the dropdown using the keyboard", function() {
|
|
93
|
+
expect(getSelectedFlagContainer()).not.toHaveAttr('tabindex');
|
|
94
|
+
expect(getSelectedFlagContainer().attr('aria-disabled')).toEqual('true');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("clicking the selected flag does not open the dropdown", function() {
|
|
98
|
+
getSelectedFlagContainer()[0].click();
|
|
99
|
+
expect(getListElement()).not.toBeVisible();
|
|
100
|
+
});
|
|
101
|
+
})
|
|
@@ -52,14 +52,14 @@ describe("destroy: init plugin to test public method destroy", function() {
|
|
|
52
52
|
|
|
53
53
|
|
|
54
54
|
|
|
55
|
-
describe("destroy: init plugin with nationalMode=false and
|
|
55
|
+
describe("destroy: init plugin with nationalMode=false and autoInsertDialCode=true", function() {
|
|
56
56
|
|
|
57
57
|
beforeEach(function() {
|
|
58
58
|
intlSetup();
|
|
59
59
|
input = $("<input>").wrap("div");
|
|
60
60
|
iti = window.intlTelInput(input[0], {
|
|
61
61
|
nationalMode: false,
|
|
62
|
-
|
|
62
|
+
autoInsertDialCode: true
|
|
63
63
|
});
|
|
64
64
|
});
|
|
65
65
|
|
|
@@ -24,6 +24,10 @@ describe("allowDropdown:", function() {
|
|
|
24
24
|
expect(getListElement()).not.toExist();
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
+
if("Should not add role[combox]", function() {
|
|
28
|
+
expect(getSelectedFlagContainer()).not.toHaveAttr("role", "combobox");
|
|
29
|
+
});
|
|
30
|
+
|
|
27
31
|
it("typing a different dial code updates the flag", function() {
|
|
28
32
|
input.val("+4");
|
|
29
33
|
triggerKeyOnInput("4");
|
|
@@ -60,6 +64,10 @@ describe("allowDropdown:", function() {
|
|
|
60
64
|
});
|
|
61
65
|
});
|
|
62
66
|
|
|
67
|
+
if("Should have role[combox]", function() {
|
|
68
|
+
expect(getSelectedFlagContainer()).toHaveAttr("role", "combobox");
|
|
69
|
+
});
|
|
70
|
+
|
|
63
71
|
it("shows the arrow and generate the dropdown markup", function() {
|
|
64
72
|
expect(getSelectedFlagContainer().find(".iti__arrow")).toExist();
|
|
65
73
|
expect(getListElement()).toExist();
|