Skip to content

Allow decimal amount entry in CurrencyInput#5639

Merged
jonnalley merged 11 commits intomainfrom
OPS-currency-input-decimal-fix
May 8, 2026
Merged

Allow decimal amount entry in CurrencyInput#5639
jonnalley merged 11 commits intomainfrom
OPS-currency-input-decimal-fix

Conversation

@jonnalley
Copy link
Copy Markdown
Contributor

@jonnalley jonnalley commented May 8, 2026

What changed

Fixes a bug where users could not type a decimal amount (e.g. 5.50) in any CurrencyInput field — the decimal point was stripped on every keystroke.

Root cause: react-currency-format's onValueChange returns a numeric floatValue (e.g. 5, no trailing decimal). That number was stored in parent state and passed back as the controlled value prop, which reformatted "5.""5" on every render, making it impossible to type cents.

frontend/src/components/UI/Form/CurrencyInput/CurrencyInput.jsx

  • Added local displayValue string state, seeded from the parent value prop at mount
  • Added a skipNextSyncRef boolean ref: set to true on each user keystroke (onValueChange) so the useEffect skips the parent's round-trip echo and preserves the in-progress string (e.g. "5.")
  • A useEffect watching the parent value prop still syncs displayValue for genuine external changes (form reset, pre-fill), but skips when the ref flag is set
  • Moved handleChange above the return for readability

frontend/src/components/UI/Form/CurrencyInput/CurrencyInput.test.jsx (new file)

  • 4 unit tests: decimal preserved mid-entry, correct float propagated to setEnteredAmount, round-trip guard (both sides verified), external reset clears the input

frontend/cypress/e2e/createAgreement.cy.js

  • 1 new E2E test: navigates the agreement creation wizard to the budget line form, types 500.75, and asserts the decimal is retained in the input

Issue

#5638

How to test

Unit tests:

cd frontend
bun run test --watch=false src/components/UI/Form/CurrencyInput/CurrencyInput.test.jsx

Expected: 4 tests pass.

Manual (requires Docker stack):

  1. Navigate to any agreement → Step 3 (Budget Lines)
  2. Click the Amount field and type 500.75
  3. Verify the decimal is retained — the field should display 500.75, not 500 or 5

E2E (requires Docker stack):

cd frontend
bun run test:e2e

The new allows entering a decimal budget line amount test in createAgreement.cy.js should pass.

A11y impact

  • No accessibility-impacting changes in this PR

Screenshots

N/A — the fix is a behavioral change (decimal entry now works), not a visual change.

Definition of Done Checklist

  • OESA: Code refactored for clarity
  • OESA: Dependency rules followed
  • Automated unit tests updated and passed
  • Automated integration tests updated and passed
  • Automated quality tests updated and passed
  • Automated load tests updated and passed
  • Automated a11y tests updated and passed
  • Automated security tests updated and passed
  • 90%+ Code coverage achieved
  • Form validations updated

Links

N/A

@jonnalley jonnalley changed the title fix: allow decimal amount entry in CurrencyInput Allow decimal amount entry in CurrencyInput May 8, 2026
@jonnalley jonnalley self-assigned this May 8, 2026
Copy link
Copy Markdown
Contributor

@rajohnson90 rajohnson90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. AI PR review passed and this passed the eye test for me as well. Tested locally and things are working

@jonnalley jonnalley merged commit 3481344 into main May 8, 2026
63 checks passed
@jonnalley jonnalley deleted the OPS-currency-input-decimal-fix branch May 8, 2026 14:56
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

🎉 This PR is included in version 1.383.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants