NumberInput triggers change event with prefix or suffix in currency and percent format. #3667
IvanKalinin
started this conversation in
General
Replies: 1 comment 1 reply
-
|
This was an intentional design decision. Can you a realistic reproduction of the issue you described earlier? I believe you can solve this without having to control the component or handle any extra complexity. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Description
The
NumberInputcomponent triggers a change event with a prefixed or suffixed value when the format style iscurrencyorpercent. This makes it way harder to validate and parse form values, as we always have to remember to parse the percent or currency value into a number. And it complicates controlled input implementation. Also increases the chance of sending invalid data in a request.I think a change event should always provide the raw value.
Technically, we could take a value from the details.valueAsNumber, but in that case, the controlled input will never be formatted. Also, we have to control a few edge cases, like an empty string, and always convert a number into a string; otherwise, a number in the value will crash the app with
value.replace is not a functionerror. Also, for some reason, thepercentstyle is the number divided by 100In addition, I just accidentally discovered another bug. You cannot enter certain numbers, such as
414. The formatter will result in413.99999999999994Anyway, for the main issue, I've implemented a minimal reproduction code, and compared the behavior with mantine (and probably all of the major component libraries), where the form holds a clean value, but the input shows the expected format
Link to Reproduction (or Detailed Explanation)
https://codesandbox.io/p/sandbox/ark-ui-number-input-cdmpxv
Steps to Reproduce
Ark UI Version
5.26.1
Framework
Browser
any
Additional Information
No response
Beta Was this translation helpful? Give feedback.
All reactions