feat(NumberInput): add decimalScale prop #2375
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
close #2321
I'd like to highlight several important points regarding the current implementation:
decimalScaleallows, rounding to the nearest integer occurs. For example:<NumberInput ... value={1.28} decimalScale={1} /> => value === 1.3Is this the expected behavior?allowDecimal = falseand attempting to insert a floating-point value, the current behavior rounds down (floor) rather than to the nearest integer. This behavior was already present in the library. I've added a test case for this scenario with name"rounds float number down if not allowDecimal prop". For example:<NumberInput value={1.8}/> => value === 1. Is this the expected behavior, or should it round to the nearest integer in this case?stepcontains more decimal places than allowed bydecimalScale? Currently, I've implemented behavior wherestepgets rounded to match the number of decimal places specified indecimalScale. For example:<NumberInput step={0.08} decimalScale={1} /> => step === 0.1. Check:rounds up step valueandrounds down step valuetests. However, would it be more appropriate to throw an error for an invalidstepconfiguration?