GoncharukBro / react-input

98 stars 7 forks source link

Removing the last character of an initially invalid value messes up whole value #6

Open SpadarShut opened 1 year ago

SpadarShut commented 1 year ago

Sandbox: https://codesandbox.io/s/react-input-mask-react-hook-form-bug-forked-wxrp98?file=/src/App.js

Steps to reproduce:

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>
  );
}
matrixmandeep commented 7 months ago

I am also experiencing the same issue. Have you found any solution for this?

SpadarShut commented 7 months ago

@matrixmandeep It seems I ended up preparing the initial value to be valid.