Skip to content
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

NumericInput clamping issue #6315

Closed
SquareByte opened this issue Aug 3, 2023 · 3 comments
Closed

NumericInput clamping issue #6315

SquareByte opened this issue Aug 3, 2023 · 3 comments

Comments

@SquareByte
Copy link

Environment

  • Package version(s): 5.0.0
  • Operating System: Ubuntu Desktop Linux
  • Browser name and version: Firefox 115, Chromium 115

Code Sandbox

https://codesandbox.io/s/elegant-easley-rgls9k?file=/src/App.tsx

Actual behavior

NumericInput shows "0" on initial render when passed props stepSize={0.000001} minorStepSize={null} majorStepSize={null} value={0.001} (the latter making it a controlled input).

Then on input focus the desired value suddenly pops up.

Expected behavior

Show the value 0.001.

Possible solution

  1. At least NumericInput.roundAndClampValue is broken, because stepMaxPrecision is not passed to toLocaleStrings option argument maximumFractionDigits.
// in getDerivedStateFromProps():
const sanitizedValue = NumericInput.roundAndClampValue(/*value=*/"0.001", /*stepMaxPrecision=*/6, 0, 1, 0, "en")
// sanitizedValue is now "0"
  1. Conceptually: as far as I understand it, minor/major/stepSize mix two distinct concerns: UI and data validation. For example: The user cannot control floats of arbitrary precision, and at the same time have a minorStepSize of say 0.01 for convenient input.
@PetrusAsikainen
Copy link
Contributor

I think this is a dupe of #4497?

@SquareByte
Copy link
Author

@PetrusAsikainen Yes, looks like it. Thank you.

I didn't recognized it because this issue focused on the button behavior. But the core issue is the same and more general, independent of the buttons. My sandbox has buttonPosition="none" set.

@TheRayTracer
Copy link

This is a better dup: #4045

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants