Skip to content

Commit

Permalink
fix: force rounding input numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
GarageInc committed Nov 7, 2024
1 parent 50ed35e commit 4cf142d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion libs/ui-kit/src/lib/modal-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
InputHTMLAttributes,
ReactNode,
useCallback,
useMemo,
} from 'react';
import clsx from 'clsx';
import MaskedInput from 'react-text-mask';
Expand All @@ -29,7 +30,13 @@ const CurrencyInput = ({
...maskOptions,
});

return <MaskedInput mask={currencyMask} {...inputProps} />;
const inputValue = useMemo(() => {
// Hack, because react-text-mask doesn't work with correct with decimals
// ex: it converts 0.0709 to 0.070 (not 0.071!)
return inputProps.value ? Number(inputProps.value).toFixed(3) : undefined;
}, [inputProps.value]);

return <MaskedInput mask={currencyMask} {...inputProps} value={inputValue} />;
};

export function StringInput({
Expand Down

0 comments on commit 4cf142d

Please sign in to comment.