Open pedroapfilho opened 6 months ago
UPDATE: it seems that removing these lines make it work as expected: https://github.com/s-yadav/react-number-format/blob/master/src/utils.tsx#L516-L528
Hey @pedroapfilho, the issue is that RNF currently works partially controlled and partially uncontrolled way. And in this case, when used floatValue on the state, 10.10000
is actually treated as just 10.1
in javascript numbers. So basically the value prop is coming back as 10.1
updating the rendered input.
Try pasting 10.10000
in console, it would be printed as 10.1
Prior to v5 it used to work, because we were comparing floatValue coming from prop and floatValue inside the state, if that not changed we were not rendering the input. But that had some other bugs.
To unblock yourself, I would suggest that for state management use a numeric string value and on submit convert it to a number, Or you can have a custom component which manages the string state and passes the numeric value to parent. Here's an example: https://codesandbox.io/p/sandbox/flamboyant-poitras-forked-4j4rzs?file=%2Fsrc%2FApp.js%3A30%2C42
Doing it this way introduces some other bugs, in the end it was flaky, and didn't pass the tests that were created to prior. It would be nice to have it fixecd on v6. I'm willing to sponsor the project to make it happen.
Describe the issue and the actual behavior
Currently, while integrating a
NumberFormatBase
withuseNumericFormat
, and usingreact-number-format
, there's one edge case where we need the value to be a number, and when we type something like10.10001
and thenbackspace
, it goes to10.1
, and not to10.000
, as expected.https://github.com/s-yadav/react-number-format/assets/13142568/4b48c489-0c3b-4388-b400-4902fbdc1ffd
Provide a CodeSandbox link illustrating the issue
https://codesandbox.io/p/sandbox/flamboyant-poitras-c7nkld?file=%2Fsrc%2FApp.js%3A24%2C1
Provide steps to reproduce this issue
Type backspace on the input
Please check the browsers where the issue is seen