Fix form-numeric-input missing decimal places
This commit is contained in:
@@ -132,6 +132,18 @@ const FormNumericInput = React.forwardRef<HTMLInputElement, NumericInputProps>(
|
|||||||
setShowWarning(hasWarning)
|
setShowWarning(hasWarning)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure value is consistently formatted to the required decimal places
|
||||||
|
React.useEffect(() => {
|
||||||
|
const strVal = String(value)
|
||||||
|
if (strVal === '') return
|
||||||
|
const num = Number(strVal)
|
||||||
|
if (isNaN(num)) return
|
||||||
|
const formatted = num.toFixed(decimalPlaces)
|
||||||
|
if (strVal !== formatted) {
|
||||||
|
onChange(formatted)
|
||||||
|
}
|
||||||
|
}, [value, decimalPlaces, onChange])
|
||||||
|
|
||||||
const getAlignmentClass = () => {
|
const getAlignmentClass = () => {
|
||||||
switch (align) {
|
switch (align) {
|
||||||
case 'left': return 'text-left'
|
case 'left': return 'text-left'
|
||||||
|
|||||||
Reference in New Issue
Block a user