Skip to content

Commit

Permalink
Fix: select Asland Islands, type +358, shows Finland
Browse files Browse the repository at this point in the history
  • Loading branch information
jackocnr committed Dec 8, 2024
1 parent b8174f5 commit 8b2894b
Show file tree
Hide file tree
Showing 15 changed files with 159 additions and 113 deletions.
11 changes: 7 additions & 4 deletions build/js/intlTelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -2596,14 +2596,17 @@ var factoryOutput = (() => {
const selectedDialCode = this.selectedCountryData.dialCode;
number = this._ensureHasDialCode(number);
const dialCodeMatch = this._getDialCode(number, true);
if (dialCodeMatch && dialCodeMatch === this.prevDialCodeMatch) {
return null;
}
this.prevDialCodeMatch = dialCodeMatch;
const numeric = getNumeric(number);
if (dialCodeMatch) {
if (this.prevDialCodeMatch === dialCodeMatch) {
return null;
}
this.prevDialCodeMatch = dialCodeMatch;
const dialCodeMatchNumeric = getNumeric(dialCodeMatch);
const iso2Codes = this.dialCodeToIso2Map[dialCodeMatchNumeric];
if (!selectedIso2 && this.defaultCountry && iso2Codes.includes(this.defaultCountry)) {
return this.defaultCountry;
}
const alreadySelected = selectedIso2 && iso2Codes.includes(selectedIso2) && numeric.length === dialCodeMatchNumeric.length;
const isRegionlessNanpNumber = selectedDialCode === "1" && isRegionlessNanp(numeric);
if (!isRegionlessNanpNumber && !alreadySelected) {
Expand Down
2 changes: 1 addition & 1 deletion build/js/intlTelInput.min.js

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions build/js/intlTelInputWithUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2595,14 +2595,17 @@ var factoryOutput = (() => {
const selectedDialCode = this.selectedCountryData.dialCode;
number = this._ensureHasDialCode(number);
const dialCodeMatch = this._getDialCode(number, true);
if (dialCodeMatch && dialCodeMatch === this.prevDialCodeMatch) {
return null;
}
this.prevDialCodeMatch = dialCodeMatch;
const numeric = getNumeric(number);
if (dialCodeMatch) {
if (this.prevDialCodeMatch === dialCodeMatch) {
return null;
}
this.prevDialCodeMatch = dialCodeMatch;
const dialCodeMatchNumeric = getNumeric(dialCodeMatch);
const iso2Codes = this.dialCodeToIso2Map[dialCodeMatchNumeric];
if (!selectedIso2 && this.defaultCountry && iso2Codes.includes(this.defaultCountry)) {
return this.defaultCountry;
}
const alreadySelected = selectedIso2 && iso2Codes.includes(selectedIso2) && numeric.length === dialCodeMatchNumeric.length;
const isRegionlessNanpNumber = selectedDialCode === "1" && isRegionlessNanp(numeric);
if (!isRegionlessNanpNumber && !alreadySelected) {
Expand Down
2 changes: 1 addition & 1 deletion build/js/intlTelInputWithUtils.min.js

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions react/build/IntlTelInput.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2591,14 +2591,17 @@ var Iti = class {
const selectedDialCode = this.selectedCountryData.dialCode;
number = this._ensureHasDialCode(number);
const dialCodeMatch = this._getDialCode(number, true);
if (dialCodeMatch && dialCodeMatch === this.prevDialCodeMatch) {
return null;
}
this.prevDialCodeMatch = dialCodeMatch;
const numeric = getNumeric(number);
if (dialCodeMatch) {
if (this.prevDialCodeMatch === dialCodeMatch) {
return null;
}
this.prevDialCodeMatch = dialCodeMatch;
const dialCodeMatchNumeric = getNumeric(dialCodeMatch);
const iso2Codes = this.dialCodeToIso2Map[dialCodeMatchNumeric];
if (!selectedIso2 && this.defaultCountry && iso2Codes.includes(this.defaultCountry)) {
return this.defaultCountry;
}
const alreadySelected = selectedIso2 && iso2Codes.includes(selectedIso2) && numeric.length === dialCodeMatchNumeric.length;
const isRegionlessNanpNumber = selectedDialCode === "1" && isRegionlessNanp(numeric);
if (!isRegionlessNanpNumber && !alreadySelected) {
Expand Down
11 changes: 7 additions & 4 deletions react/build/IntlTelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -2555,14 +2555,17 @@ var Iti = class {
const selectedDialCode = this.selectedCountryData.dialCode;
number = this._ensureHasDialCode(number);
const dialCodeMatch = this._getDialCode(number, true);
if (dialCodeMatch && dialCodeMatch === this.prevDialCodeMatch) {
return null;
}
this.prevDialCodeMatch = dialCodeMatch;
const numeric = getNumeric(number);
if (dialCodeMatch) {
if (this.prevDialCodeMatch === dialCodeMatch) {
return null;
}
this.prevDialCodeMatch = dialCodeMatch;
const dialCodeMatchNumeric = getNumeric(dialCodeMatch);
const iso2Codes = this.dialCodeToIso2Map[dialCodeMatchNumeric];
if (!selectedIso2 && this.defaultCountry && iso2Codes.includes(this.defaultCountry)) {
return this.defaultCountry;
}
const alreadySelected = selectedIso2 && iso2Codes.includes(selectedIso2) && numeric.length === dialCodeMatchNumeric.length;
const isRegionlessNanpNumber = selectedDialCode === "1" && isRegionlessNanp(numeric);
if (!isRegionlessNanpNumber && !alreadySelected) {
Expand Down
11 changes: 7 additions & 4 deletions react/build/IntlTelInputWithUtils.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2591,14 +2591,17 @@ var Iti = class {
const selectedDialCode = this.selectedCountryData.dialCode;
number = this._ensureHasDialCode(number);
const dialCodeMatch = this._getDialCode(number, true);
if (dialCodeMatch && dialCodeMatch === this.prevDialCodeMatch) {
return null;
}
this.prevDialCodeMatch = dialCodeMatch;
const numeric = getNumeric(number);
if (dialCodeMatch) {
if (this.prevDialCodeMatch === dialCodeMatch) {
return null;
}
this.prevDialCodeMatch = dialCodeMatch;
const dialCodeMatchNumeric = getNumeric(dialCodeMatch);
const iso2Codes = this.dialCodeToIso2Map[dialCodeMatchNumeric];
if (!selectedIso2 && this.defaultCountry && iso2Codes.includes(this.defaultCountry)) {
return this.defaultCountry;
}
const alreadySelected = selectedIso2 && iso2Codes.includes(selectedIso2) && numeric.length === dialCodeMatchNumeric.length;
const isRegionlessNanpNumber = selectedDialCode === "1" && isRegionlessNanp(numeric);
if (!isRegionlessNanpNumber && !alreadySelected) {
Expand Down
11 changes: 7 additions & 4 deletions react/build/IntlTelInputWithUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2555,14 +2555,17 @@ var Iti = class {
const selectedDialCode = this.selectedCountryData.dialCode;
number = this._ensureHasDialCode(number);
const dialCodeMatch = this._getDialCode(number, true);
if (dialCodeMatch && dialCodeMatch === this.prevDialCodeMatch) {
return null;
}
this.prevDialCodeMatch = dialCodeMatch;
const numeric = getNumeric(number);
if (dialCodeMatch) {
if (this.prevDialCodeMatch === dialCodeMatch) {
return null;
}
this.prevDialCodeMatch = dialCodeMatch;
const dialCodeMatchNumeric = getNumeric(dialCodeMatch);
const iso2Codes = this.dialCodeToIso2Map[dialCodeMatchNumeric];
if (!selectedIso2 && this.defaultCountry && iso2Codes.includes(this.defaultCountry)) {
return this.defaultCountry;
}
const alreadySelected = selectedIso2 && iso2Codes.includes(selectedIso2) && numeric.length === dialCodeMatchNumeric.length;
const isRegionlessNanpNumber = selectedDialCode === "1" && isRegionlessNanp(numeric);
if (!isRegionlessNanpNumber && !alreadySelected) {
Expand Down
11 changes: 7 additions & 4 deletions react/demo/set-number/set-number-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -26142,14 +26142,17 @@
const selectedDialCode = this.selectedCountryData.dialCode;
number = this._ensureHasDialCode(number);
const dialCodeMatch = this._getDialCode(number, true);
if (dialCodeMatch && dialCodeMatch === this.prevDialCodeMatch) {
return null;
}
this.prevDialCodeMatch = dialCodeMatch;
const numeric = getNumeric(number);
if (dialCodeMatch) {
if (this.prevDialCodeMatch === dialCodeMatch) {
return null;
}
this.prevDialCodeMatch = dialCodeMatch;
const dialCodeMatchNumeric = getNumeric(dialCodeMatch);
const iso2Codes = this.dialCodeToIso2Map[dialCodeMatchNumeric];
if (!selectedIso2 && this.defaultCountry && iso2Codes.includes(this.defaultCountry)) {
return this.defaultCountry;
}
const alreadySelected = selectedIso2 && iso2Codes.includes(selectedIso2) && numeric.length === dialCodeMatchNumeric.length;
const isRegionlessNanpNumber = selectedDialCode === "1" && isRegionlessNanp(numeric);
if (!isRegionlessNanpNumber && !alreadySelected) {
Expand Down
11 changes: 7 additions & 4 deletions react/demo/simple/simple-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -26142,14 +26142,17 @@
const selectedDialCode = this.selectedCountryData.dialCode;
number = this._ensureHasDialCode(number);
const dialCodeMatch = this._getDialCode(number, true);
if (dialCodeMatch && dialCodeMatch === this.prevDialCodeMatch) {
return null;
}
this.prevDialCodeMatch = dialCodeMatch;
const numeric = getNumeric(number);
if (dialCodeMatch) {
if (this.prevDialCodeMatch === dialCodeMatch) {
return null;
}
this.prevDialCodeMatch = dialCodeMatch;
const dialCodeMatchNumeric = getNumeric(dialCodeMatch);
const iso2Codes = this.dialCodeToIso2Map[dialCodeMatchNumeric];
if (!selectedIso2 && this.defaultCountry && iso2Codes.includes(this.defaultCountry)) {
return this.defaultCountry;
}
const alreadySelected = selectedIso2 && iso2Codes.includes(selectedIso2) && numeric.length === dialCodeMatchNumeric.length;
const isRegionlessNanpNumber = selectedDialCode === "1" && isRegionlessNanp(numeric);
if (!isRegionlessNanpNumber && !alreadySelected) {
Expand Down
11 changes: 7 additions & 4 deletions react/demo/toggle-disabled/toggle-disabled-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -26142,14 +26142,17 @@
const selectedDialCode = this.selectedCountryData.dialCode;
number = this._ensureHasDialCode(number);
const dialCodeMatch = this._getDialCode(number, true);
if (dialCodeMatch && dialCodeMatch === this.prevDialCodeMatch) {
return null;
}
this.prevDialCodeMatch = dialCodeMatch;
const numeric = getNumeric(number);
if (dialCodeMatch) {
if (this.prevDialCodeMatch === dialCodeMatch) {
return null;
}
this.prevDialCodeMatch = dialCodeMatch;
const dialCodeMatchNumeric = getNumeric(dialCodeMatch);
const iso2Codes = this.dialCodeToIso2Map[dialCodeMatchNumeric];
if (!selectedIso2 && this.defaultCountry && iso2Codes.includes(this.defaultCountry)) {
return this.defaultCountry;
}
const alreadySelected = selectedIso2 && iso2Codes.includes(selectedIso2) && numeric.length === dialCodeMatchNumeric.length;
const isRegionlessNanpNumber = selectedDialCode === "1" && isRegionlessNanp(numeric);
if (!isRegionlessNanpNumber && !alreadySelected) {
Expand Down
11 changes: 7 additions & 4 deletions react/demo/validation/validation-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -26142,14 +26142,17 @@
const selectedDialCode = this.selectedCountryData.dialCode;
number = this._ensureHasDialCode(number);
const dialCodeMatch = this._getDialCode(number, true);
if (dialCodeMatch && dialCodeMatch === this.prevDialCodeMatch) {
return null;
}
this.prevDialCodeMatch = dialCodeMatch;
const numeric = getNumeric(number);
if (dialCodeMatch) {
if (this.prevDialCodeMatch === dialCodeMatch) {
return null;
}
this.prevDialCodeMatch = dialCodeMatch;
const dialCodeMatchNumeric = getNumeric(dialCodeMatch);
const iso2Codes = this.dialCodeToIso2Map[dialCodeMatchNumeric];
if (!selectedIso2 && this.defaultCountry && iso2Codes.includes(this.defaultCountry)) {
return this.defaultCountry;
}
const alreadySelected = selectedIso2 && iso2Codes.includes(selectedIso2) && numeric.length === dialCodeMatchNumeric.length;
const isRegionlessNanpNumber = selectedDialCode === "1" && isRegionlessNanp(numeric);
if (!isRegionlessNanpNumber && !alreadySelected) {
Expand Down
18 changes: 13 additions & 5 deletions src/js/intl-tel-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1441,15 +1441,23 @@ export class Iti {

//* Try and extract valid dial code (plus area code digits) from input.
const dialCodeMatch = this._getDialCode(number, true);
if (dialCodeMatch && dialCodeMatch === this.prevDialCodeMatch) {
//* Optimisation: if there is a dial code match and it's the same as last time, no need to do anything.
return null;
}
this.prevDialCodeMatch = dialCodeMatch;

const numeric = getNumeric(number);
if (dialCodeMatch) {
if (this.prevDialCodeMatch === dialCodeMatch) {
//* Optimisation: if dialCodeMatch is same, no need to do anything.
return null;
}
this.prevDialCodeMatch = dialCodeMatch;
const dialCodeMatchNumeric = getNumeric(dialCodeMatch);
const iso2Codes = this.dialCodeToIso2Map[dialCodeMatchNumeric];

//* If they've just typed a dial code (from empty state), and it matches the last selected country, then stick to that country.
//* e.g. if they select Aland Islands, then type it's dial code +358, we should stick to that country and not switch to Finland!
if (!selectedIso2 && this.defaultCountry && iso2Codes.includes(this.defaultCountry)) {
return this.defaultCountry;
}

//* Check if the right country is already selected (note: might be empty state - globe icon).
//* NOTE: the number of digits typed can only be the same as or more than the matched dial code (plus area code) digits
//* If they're the same length, that's a perfect match. Otherwise, they've typed more digits than the best match, in which case we should default to the first country that fits the matched dial code.
Expand Down
Loading

0 comments on commit 8b2894b

Please sign in to comment.