I've been attempting to integrate the google-libphonenumber's AsYouTypeFormatter
into a basic input field on a web form. For each key pressed by the user, I feed it into the inputDigit
method. However, I've encountered an issue where when the user hits the backspace key, google-libphonenumber doesn't correctly remove the last digit and simply adds "Backspace" to the phone number. Could it be that I'm incorrectly implementing the AsYouTypeFormatter? Does it lack support for handling backspaces? If so, which approach should I take in dealing with backspace key presses?
To see a sample project showcasing this issue, you can visit: https://stackblitz.com/edit/libphonenumber
Below is the code snippet being used:
import { AsYouTypeFormatter } from 'google-libphonenumber';
const appDiv: HTMLElement = document.getElementById('app');
appDiv.innerHTML = `
<h1>Libphonenumber Playground</h1>
<input id="input" type="text">
`;
this.formatter = new AsYouTypeFormatter('us');
const input = document.getElementById('input') as HTMLInputElement;
input.addEventListener('keyup', (event: KeyboardEvent) => {
console.log(this.formatter.inputDigit(event.key));
});