Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

618 Solve a case when prefix is active, and a user has selected all t… #619

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,11 @@ class PhoneInput extends React.Component {

if (lastChar == ')') {
this.numberInputRef.setSelectionRange(formattedNumber.length - 1, formattedNumber.length - 1);
} else if (caretPosition === 1 && !this.props.disableCountryCode) {
// https://github.com/bl00mber/react-phone-input-2/issues/618
// Solve a case when prefix is active, and a user has selected all text and types to overwrite. In this caret caret should be placed after entered input, so add length of prefix to the caretPosition
caretPosition += (prefix ? prefix.length : 0);
this.numberInputRef.setSelectionRange(caretPosition, caretPosition);
} else if (caretPosition > 0 && oldFormattedText.length >= formattedNumber.length) {
this.numberInputRef.setSelectionRange(caretPosition, caretPosition);
} else if (oldCaretPosition < oldFormattedText.length) {
Expand Down