react-input
react-input copied to clipboard
Removing the last character of an initially invalid value messes up whole value
trafficstars
Sandbox: https://codesandbox.io/s/react-input-mask-react-hook-form-bug-forked-wxrp98?file=/src/App.js
Steps to reproduce:
- Open a form with default values, where an initial value does not match the mask
- place cursor at the end of the input, remove last character
Expected result: Last character is removed
Actual result:
The string is mangled: from +1 559-386-2345 to (153) 823-4
The code
import { useMask } from "@react-input/mask";
export default function App() {
const maskRef = useMask({
mask: "(___) ___-____",
replacement: { _: /\d/ }
});
return (
<form>
<input defaultValue="+1 559-386-2345" ref={maskRef} type="text" />
</form>
);
}
I am also experiencing the same issue. Have you found any solution for this?
@matrixmandeep It seems I ended up preparing the initial value to be valid.