catamphetamine / libphonenumber-js

A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript
https://catamphetamine.gitlab.io/libphonenumber-js/
MIT License
2.79k stars 216 forks source link

Unable to backspace at parenthesis with AsYouType formatting #224

Closed jharsono closed 6 years ago

jharsono commented 6 years ago

When I have US phone number in an input field, I can't backspace over a parenthesis. Clicking inside the parenthesis allows me to backspace one number, then jumps the cursor back to the space after the parenthesis.

catamphetamine commented 6 years ago

This library only contains pure javascript functions. It doesn't contain any input functionality.

jharsono commented 6 years ago

Thank you - I will double check with my input field implementation.

catamphetamine commented 6 years ago

Btw, recently I released a "without country select, just phone input" component. https://github.com/catamphetamine/react-phone-number-input/#without-country-select Seems to be no issues.

jharsono commented 6 years ago

I found my issue: When I was passing numbers into the AsYouType, I was passing the entire value of the field, so when you backspace on the parenthesis, the formatter still evaluates the 3 numbers and puts the parenthesis back in. I just added a conditional to only start formatting after 3 numbers have been typed. Specifically for when using US phone number format.

catamphetamine commented 6 years ago

I see )