Skip to content

Commit

Permalink
drop setSelectionRange() check #50
Browse files Browse the repository at this point in the history
  • Loading branch information
bl00mber committed Feb 17, 2019
1 parent d6713ed commit b2dd8f1
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ class ReactPhoneInput extends React.Component {

onEnterKeyPress: () => {},

isModernBrowser: document.createElement ? (
Boolean(document.createElement('input').setSelectionRange)
) : false,

keys: {
UP: 38, DOWN: 40, RIGHT: 39, LEFT: 37, ENTER: 13,
ESC: 27, PLUS: 43, A: 65, Z: 90, SPACE: 32
Expand Down Expand Up @@ -409,10 +405,8 @@ class ReactPhoneInput extends React.Component {
cursorToEnd = () => {
const input = this.numberInputRef;
input.focus();
if (this.props.isModernBrowser) {
const len = input.value.length;
input.setSelectionRange(len, len);
}
const len = input.value.length;
input.setSelectionRange(len, len);
}

getElement = (index) => {
Expand Down Expand Up @@ -505,19 +499,17 @@ class ReactPhoneInput extends React.Component {
? newSelectedCountry
: this.state.selectedCountry
}, () => {
if (this.props.isModernBrowser) {
if (diff > 0) {
caretPosition = caretPosition - diff;
}
if (diff > 0) {
caretPosition = caretPosition - diff;
}

const lastChar = formattedNumber.charAt(formattedNumber.length - 1);
const lastChar = formattedNumber.charAt(formattedNumber.length - 1);

if (lastChar == ')') {
this.numberInputRef.setSelectionRange(formattedNumber.length - 1, formattedNumber.length - 1);
}
else if (caretPosition > 0 && oldFormattedText.length >= formattedNumber.length) {
this.numberInputRef.setSelectionRange(caretPosition, caretPosition);
}
if (lastChar == ')') {
this.numberInputRef.setSelectionRange(formattedNumber.length - 1, formattedNumber.length - 1);
}
else if (caretPosition > 0 && oldFormattedText.length >= formattedNumber.length) {
this.numberInputRef.setSelectionRange(caretPosition, caretPosition);
}

if (this.props.onChange) {
Expand Down

0 comments on commit b2dd8f1

Please sign in to comment.