Skip to content

Commit

Permalink
fixed overlapping flags problem when the input field was used for mor…
Browse files Browse the repository at this point in the history
…e than one number in single form
  • Loading branch information
mukeshsoni committed Oct 10, 2016
1 parent fd4e847 commit fb94c41
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
8 changes: 4 additions & 4 deletions less/default.less
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@
.v-hide {
visibility: hidden;
}
input[type=text],
input[type=text],
input[type=tel] {
position: relative;
z-index: 0;
Expand Down Expand Up @@ -797,7 +797,7 @@
.country-list {
list-style: none;
position: absolute;
z-index: 2;
z-index: 15;
padding: 0;
margin: -1px 0 0 -1px;
box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.2);
Expand Down Expand Up @@ -835,5 +835,5 @@
.country-name {
margin-right: 6px;
}
}
}
}
}
15 changes: 14 additions & 1 deletion lib/ReactTelephoneInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ var ReactTelephoneInput = React.createClass({
selectedCountry: newSelectedCountry.dialCode.length > 0 ? newSelectedCountry : this.state.selectedCountry
}, function () {
if (isModernBrowser) {
if (caretPosition === 1 && formattedNumber.length === 2) {
caretPosition++;
}

if (diff > 0) {
caretPosition = caretPosition - diff;
}
Expand Down Expand Up @@ -350,7 +354,16 @@ var ReactTelephoneInput = React.createClass({
this._fillDialCode();
},
_mapPropsToState: function _mapPropsToState(props) {
var inputNumber = props.initialValue || props.value || '';
var inputNumber = undefined;

if (props.value !== this.props.value) {
inputNumber = props.initialValue;
} else if (props.initialValue !== this.props.initialValue) {
inputNumber = props.initialValue;
} else {
inputNumber = '';
}

var selectedCountryGuess = this.guessSelectedCountry(inputNumber.replace(/\D/g, ''));
var selectedCountryGuessIndex = findIndex(allCountries, selectedCountryGuess);
var formattedNumber = this.formatNumber(inputNumber.replace(/\D/g, ''), selectedCountryGuess ? selectedCountryGuess.format : null);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-telephone-input",
"version": "3.6.2",
"version": "3.6.3",
"description": "React component for entering and validating international telephone numbers",
"main": "lib/ReactTelephoneInput.js",
"scripts": {
Expand Down

0 comments on commit fb94c41

Please sign in to comment.