Skip to content

Commit dcd67fd

Browse files
committed
disableCountryGuess, #271, close #287
1 parent f01f5d1 commit dcd67fd

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,10 @@ If `enableAreaCodeStretch` is added, the part of the mask with the area code wil
395395
<td> disableInitialCountryGuess </td>
396396
<td> false </td>
397397
</tr>
398+
<tr>
399+
<td> disableCountryGuess </td>
400+
<td> false </td>
401+
</tr>
398402
</table>
399403

400404
### Custom localization

src/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class PhoneInput extends React.Component {
5959
enableSearch: PropTypes.bool,
6060
disableSearchIcon: PropTypes.bool,
6161
disableInitialCountryGuess: PropTypes.bool,
62+
disableCountryGuess: PropTypes.bool,
6263

6364
regions: PropTypes.oneOfType([
6465
PropTypes.string,
@@ -133,6 +134,7 @@ class PhoneInput extends React.Component {
133134
enableSearch: false,
134135
disableSearchIcon: false,
135136
disableInitialCountryGuess: false,
137+
disableCountryGuess: false,
136138

137139
regions: '',
138140

@@ -329,7 +331,10 @@ class PhoneInput extends React.Component {
329331
this.setState({ formattedNumber });
330332
}
331333
else {
332-
newSelectedCountry = this.guessSelectedCountry(inputNumber.substring(0, 6), country, onlyCountries, hiddenAreaCodes) || selectedCountry;
334+
if (this.props.disableCountryGuess) {newSelectedCountry = selectedCountry;}
335+
else {
336+
newSelectedCountry = this.guessSelectedCountry(inputNumber.substring(0, 6), country, onlyCountries, hiddenAreaCodes) || selectedCountry;
337+
}
333338
const dialCode = newSelectedCountry && startsWith(inputNumber, prefix + newSelectedCountry.dialCode) ? newSelectedCountry.dialCode : '';
334339

335340
formattedNumber = this.formatNumber(
@@ -547,7 +552,10 @@ class PhoneInput extends React.Component {
547552
// the guess country function can then use memoization much more effectively since the set of input it
548553
// gets has drastically reduced
549554
if (!this.state.freezeSelection || selectedCountry.dialCode.length > inputNumber.length) {
550-
newSelectedCountry = this.guessSelectedCountry(inputNumber.substring(0, 6), country, onlyCountries, hiddenAreaCodes) || selectedCountry;
555+
if (this.props.disableCountryGuess) {newSelectedCountry = selectedCountry;}
556+
else {
557+
newSelectedCountry = this.guessSelectedCountry(inputNumber.substring(0, 6), country, onlyCountries, hiddenAreaCodes) || selectedCountry;
558+
}
551559
freezeSelection = false;
552560
}
553561
formattedNumber = this.formatNumber(inputNumber, newSelectedCountry);

0 commit comments

Comments
 (0)