Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class CurrencyInput extends Component {
this.prepareProps = this.prepareProps.bind(this);
this.handleChange = this.handleChange.bind(this);
this.handleFocus = this.handleFocus.bind(this);
this.setSelectionRange = this.setSelectionRange.bind(this);
this.state = this.prepareProps(this.props);

this.inputSelectionStart = 1;
Expand Down Expand Up @@ -130,7 +131,7 @@ class CurrencyInput extends Component {
selectionStart = Math.min(node.selectionStart, selectionEnd);
}

node.setSelectionRange(selectionStart, selectionEnd);
this.setSelectionRange(node, selectionStart, selectionEnd);
}


Expand Down Expand Up @@ -182,11 +183,23 @@ class CurrencyInput extends Component {
selectionStart = selectionEnd;
}

node.setSelectionRange(selectionStart, selectionEnd);
this.setSelectionRange(node, selectionStart, selectionEnd);
this.inputSelectionStart = selectionStart;
this.inputSelectionEnd = selectionEnd;
}

/**
* Set selection range only if input is in focused state
* @param node DOMElement
* @param start number
* @param end number
*/
setSelectionRange(node, start, end) {
if (document.activeElement === node) {
node.setSelectionRange(start, end);
}
}


/**
* onChange Event Handler
Expand Down