) => {
if (e.key === 'Enter') {
- // Try to evaluate as math expression first
- const mathResult = evaluateMathExpression(displayValue);
- const valueInCents = mathResult !== null ? mathResult : parseInputValue(displayValue);
-
- onChange(valueInCents);
+ onChange(resolveCents(displayValue));
}
};
+ // iOS numeric keypads (inputMode="decimal") have no minus key, so
+ // negative amounts need an explicit toggle. onClick handles both pointer
+ // and keyboard; onPointerDown preventDefault keeps the input focused,
+ // avoiding the blur/reformat race with the effect above.
+ const toggleSign = () => {
+ const next = displayValue.trim().startsWith('-')
+ ? displayValue.replace('-', '')
+ : `-${displayValue}`;
+ setDisplayValue(next);
+ onChange(resolveCents(next));
+ };
+
+ const isNegative = displayValue.trim().startsWith('-');
+
const { symbol: currencySymbol, position: symbolPosition } = getCurrencyInfo(currencyCode, locale);
return (
{symbolPosition === 'prefix' && (
-
+
{currencySymbol}
)}
@@ -239,7 +256,12 @@ export const AmountInput = React.forwardRef(
required={required}
className={cn([
'bg-background',
- symbolPosition === 'prefix' ? 'pl-9' : 'pr-9',
+ symbolPosition === 'suffix' && 'pr-9',
+ allowNegative
+ ? symbolPosition === 'prefix'
+ ? 'pl-14'
+ : 'pl-11'
+ : symbolPosition === 'prefix' && 'pl-9',
className,
])}
/>
@@ -248,6 +270,24 @@ export const AmountInput = React.forwardRef(
{currencySymbol}
)}
+ {allowNegative && (
+
+ )}
);
},