Fix form-numeric-input missing decimal places

This commit is contained in:
2025-12-03 22:27:09 +00:00
parent e398b1cb29
commit 41ffce1c23

View File

@@ -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'