Skip to content

Commit

Permalink
Merge pull request #313 from Kongfujonstew/fix-delete-err
Browse files Browse the repository at this point in the history
Bug fix: Bypass formatNumber if user is deleting
  • Loading branch information
patw0929 committed Feb 29, 2020
2 parents 34193af + d212b78 commit 02e635d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/components/IntlTelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -1205,13 +1205,21 @@ class IntlTelInput extends Component {
// or udpate the state and notify change if component is uncontrolled
handleInputChange = e => {
let cursorPosition = e.target.selectionStart;
// previous value is pre formatted value
const previousValue = e.target.value;
// prior value is existing state value/ before update
const priorValue = this.state.value;
const previousStringBeforeCursor =
previousValue === ''
? previousValue
: previousValue.substring(0, cursorPosition);

// Don't format if user is deleting chars
const formattedValue = previousValue.length < priorValue.length
? previousValue
: this.formatNumber(e.target.value);
const value = this.props.format
? this.formatNumber(e.target.value)
? formattedValue
: e.target.value;

cursorPosition = utils.getCursorPositionAfterFormating(
Expand Down

0 comments on commit 02e635d

Please sign in to comment.