-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
InputNumber: onChange parameter type #5037
Comments
I agree with you that the type of string inside NumberInput make weird typings and mappings.
onChange={(val) => onChange(val === '' ? undefined : (val as number))}
onChange={(val) => onChange(val === '' ? null : (val as number))}
onChange={(val) => onChange(val as number)} The last one has issues of course. |
Also the type of the value changes to number when you use the arrow buttons to increase and decrease the value, and it changes back to string when you use your keyboard to type numbers. |
…with number unless the input is empty (#5037)
Fixed in 7.2.2 |
What package has an issue
@mantine/core
Describe the bug
I noticed that in the latest version onChange in InputNumber is called with a string as its parameter when defaultValue is undefined. I am not sure this is correct, and it is definitely not correct for my situation.
Although of course there is a simple workaround. The problem for me is that I do not think that current behaviour is correct.
What version of @mantine/* packages do you have in package.json? (Note that all @mantine/* packages must have the same version in order to work correctly)
7.1.3
If possible, please include a link to a codesandbox with the reproduced problem
https://codesandbox.io/s/mantine-forked-xq74sl?file=/src/App.tsx
Do you know how to fix the issue
None
Are you willing to participate in fixing this issue and create a pull request with the fix
None
Possible fix
I found a PR that introduced this change: #4916
Possibly, when _value is undefined, we should pass a number to onChange. What do you think? Although I did not test this solution for these issues: #4901 , #4912
And to be honest, I am not sure that we should ever pass a string as a parameter to onChange (except maybe when there is no value, but in this case null is a better option from my point of view) - this is NumberInput after all =)
The text was updated successfully, but these errors were encountered: