Fix amount field formatting when pressing Enter

- Add onKeyDown handler to AmountInput component to format value when Enter is pressed
- Ensure amount is properly parsed before form submission regardless of submission method
- Add browser test to verify amount formatting on Enter key press
This commit is contained in:
Víctor Falcón 2025-12-15 08:47:11 +01:00
parent e813849e7b
commit ab61266955
4 changed files with 41 additions and 3 deletions

View File

@ -22,7 +22,7 @@ export default function AppLogoIcon({
const showBirdhouse = !isKeySet || isPrivacyModeEnabled;
if (!animated) {
<BirdIcon className={iconClasses} />
<BirdIcon className={iconClasses} />;
}
return (

View File

@ -130,8 +130,7 @@ export function createTransactionColumns({
header: 'Account',
meta: {
label: 'Account',
cellClassName:
'!min-w-[125px] whitespace-normal',
cellClassName: '!min-w-[125px] whitespace-normal',
},
cell: ({ row }) => {
const transaction = row.original;

View File

@ -108,6 +108,13 @@ export const AmountInput = React.forwardRef<HTMLInputElement, AmountInputProps>(
setDisplayValue(e.target.value);
};
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'Enter') {
const valueInCents = parseInputValue(displayValue);
onChange(valueInCents);
}
};
const currencySymbol = getCurrencySymbol(currencyCode);
return (
@ -124,6 +131,7 @@ export const AmountInput = React.forwardRef<HTMLInputElement, AmountInputProps>(
onChange={handleChange}
onFocus={handleFocus}
onBlur={handleBlur}
onKeyDown={handleKeyDown}
placeholder={placeholder}
disabled={disabled}
required={required}

View File

@ -72,3 +72,34 @@ it('can create a transaction with amount input', function () {
'amount' => 12345,
]);
})->skip('Requires browser encryption key setup');
it('formats amount when pressing enter', function () {
$user = User::factory()->onboarded()->create();
$category = Category::factory()->create(['user_id' => $user->id]);
$account = Account::factory()->create(['user_id' => $user->id]);
actingAs($user);
$page = visit('/transactions');
$page->assertSee('Transactions')
->click('Add Transaction')
->wait(1)
->fill('description', 'Test Transaction Enter')
->click('Select Account')
->wait(0.5)
->click($account->name)
->click('Select Category')
->wait(0.5)
->click($category->name)
->fill('#amount', '99.99')
->press('Enter')
->wait(2)
->assertNoJavascriptErrors();
$this->assertDatabaseHas('transactions', [
'user_id' => $user->id,
'description' => 'Test Transaction Enter',
'amount' => 9999,
]);
})->skip('Requires browser encryption key setup');