Skip to content

Commit

Permalink
fix(intl-phone-input): revert fix carret position on backspace
Browse files Browse the repository at this point in the history
  • Loading branch information
reme3d2y committed Sep 30, 2021
1 parent 10284a0 commit 772dcf5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/intl-phone-input/src/usePreventCaretReset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ export function usePreventCaretReset({ inputRef, clearableCountryCode, countryCo
const input = event.target as HTMLInputElement;
const caretPosition = input.selectionStart;

if (event.key === 'ArrowRight' || event.key === 'ArrowLeft' || !caretPosition) return;
if (event.key !== 'Backspace' || !caretPosition) return;

if (!clearableCountryCode && caretPosition <= countryCodeLength) {
event.preventDefault();

return;
}

const newPosition = event.key === 'Backspace' ? caretPosition - 1 : caretPosition + 1;
const newPosition = caretPosition - 1;

requestAnimationFrame(() => {
input.setSelectionRange(newPosition, newPosition);
Expand Down

0 comments on commit 772dcf5

Please sign in to comment.