-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 3663 fix number input #3756
Issue 3663 fix number input #3756
Conversation
…lValue` in uncontrolled mode
I've uploaded a patched version of This shows that the issues seem to be solved. However in combination with So that's something I have to look into. |
…x glitch with `useForm()` mantinedev#3729
I've fixed the glitch with |
I'm not really sure that it is a good idea. It seems like a breaking change. I'll have a look at those issues. Most likely, we just need to turn off NumberInput formatting when it is focused. |
It's like the native inputs change event also works. If you fire So the newly required changes might be:
|
IMHO that should be done in either case as it's pretty annoying UX-wise, try changing some numbers in the "Parser and formatter" section at https://mantine.dev/core/number-input/ It just feels off somehow, cursor and numbers jump around, etc. |
Fair point @disillusionedowl, thanks for sharing your thoughts. I think we will go with @cyantree solution then – onChange will not be called until input is blurred. |
Great, thank you very much guys! The extra logic/options can always be added later behind some flags if there will be demand. The above looks like a solid default foundation. |
Thank's! I agree that it would be great to have a working base again before adding/changing other things. However honestly I don't understand the formatting issue that came up multiple times. Aspect 1: Clean formatting during editing / Spreadsheet behaviourThat's a valid point that's currently partially implemented. I think we need two layers for formatting/parsing and three layers for data representation. Consider the following example: Then after blurring the input the amount would get formatted and the unit added. If the user then wants to edit the amount again the input field would show again The internal value will always be So the data representation layers are:
You need the following converters to work with these layers:
The current approach only has the data layers 1) and 3) and the formatter/parser converts between those two. Aspect 2: Data flow handling via
|
You seem to have a good grasp on this @cyantree so it would be awesome, as you have possibly suggested, if you could continue with your work on this through other PRs, if you would be willing. Thanks again for this PR though, it's great as-is. |
Thanks! |
This fixes #3663 and #3729.
It's been quite a rework of the internal data handling so please have a closer look at it.
The key changes are:
onChange()
when bluring the component or using the increment/decrement functionality.onChange()
gets calledvalue
emitted inonChange()
now already respects precision and min/max.value
that doesn't match the configuration (either because it's precision is higher than configured or it isn't within the min/max bounds) it will be displayed as is (so not rounded or clamped). However as soon as it has been changed by the user it gets rounded/clamped again.