Skip to content

Add NumericField with NumericEditingController - #99772

Merged
mountiny merged 36 commits into
Expensify:mainfrom
software-mansion-labs:jmgraa/NumericField_NumericEditingController
Sep 9, 2026
Merged

mountiny merged 36 commits into
Expensify:mainfrom
software-mansion-labs:jmgraa/NumericField_NumericEditingController

Conversation

@jmgraa

@jmgraa jmgraa commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

This change lays the foundation for decomposing NumberWithSymbolForm by introducing the composable NumericField root and its NumericField.TextInput primitive (the implementation of the NumberForm API described in issue #98169).

The new numeric editing controller centralizes value normalization, locale digit conversion, decimal and length validation, formatting, and the existing imperative API (clearSelection, updateNumber, and getNumber). It also manages caret positioning across insertions, deletions, rejected edits, external clears, and stale native selection events. The field exposes shared state and actions through context so additional numeric primitives can be added without duplicating editing logic.

AmountForm now uses NumericField for standard text-input amounts, while currency-button variants continue using NumberWithSymbolForm. The new NumericField uses improved, centralized normalization logic, so its behavior may differ from the legacy component in some edge cases. NumberWithSymbolForm remains available with its existing behavior unchanged. Unit and UI tests cover normalization, validation, selection handling, controller behavior, and the AmountForm integration.

This PR is part 1 of 2 of the changes originally proposed in #98967 following code review, the work was split into two PRs to make the changes easier to review and merge incrementally.

Fixed Issues

$ #98169
PROPOSAL: #97970

Tests

  1. Navigate to Workspace settings → Rules → Max expense amount to open an amount form that uses the standard text-input mode, then enter a valid whole or decimal amount.
  2. Verify that the amount is formatted with the current locale's digits and decimal separator, and that the currency symbol is displayed correctly.
  3. Move the caret within the amount, insert and delete digits, and verify that the caret remains in the expected position, including when using forward delete.
  4. Enter an invalid value or exceed the configured decimal and integer limits, and verify that the edit is rejected and the last valid value and caret position are preserved.
  5. Clear the field and verify that it resets to an empty value and the caret moves to the beginning.
  6. In a flow with a currency or duration button, verify that the legacy NumberWithSymbolForm UI and behavior remain unchanged.
  • Verify that no errors appear in the JS console

Offline tests

  1. Turn off the network connection and open a form containing a standard numeric text input.
  2. Enter, edit, delete, and clear an amount while offline, and verify that normalization, validation, formatting, and caret behavior continue to work locally.
  3. Navigate away and back to the form while offline, and verify that the field does not show errors or unexpected selection changes.
  4. Re-enable the network connection and verify that the final valid value is still displayed correctly and can be submitted normally.

QA Steps

Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
Android: Native
android_native.mov
Android: mWeb Chrome
android_mweb.mov
iOS: Native
ios_native.mov
iOS: mWeb Safari
ios_mweb.mov
MacOS: Chrome / Safari
web.mov

@melvin-bot

melvin-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown

Hey! I see that you made changes to our Form component. Make sure to update the docs in FORMS.md accordingly. Cheers!

@codecov

codecov Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/components/AmountForm.tsx 100.00% <100.00%> (ø)
...ericEditingController/hooks/useNumericSelection.ts 100.00% <100.00%> (ø)
src/components/NumericEditingController/utils.ts 100.00% <100.00%> (ø)
src/components/NumericField/NumericField.tsx 100.00% <100.00%> (ø)
...onents/NumericField/context/NumericFieldContext.ts 100.00% <100.00%> (ø)
src/components/NumericField/index.tsx 100.00% <100.00%> (ø)
...nents/NumericField/primitives/NumericTextInput.tsx 100.00% <100.00%> (ø)
...ingController/hooks/useNumericEditingController.ts 96.96% <96.96%> (ø)
... and 12 files with indirect coverage changes

@jmgraa
jmgraa force-pushed the jmgraa/NumericField_NumericEditingController branch from dc0d39c to 18deab3 Compare August 28, 2026 16:02
Comment thread tests/ui/AmountFormTest.tsx Resolved
Comment thread src/components/NumericField/types.ts Resolved
Comment thread tests/ui/AmountFormTest.tsx Resolved
@jmgraa
jmgraa force-pushed the jmgraa/NumericField_NumericEditingController branch from 5480746 to 3217c70 Compare September 2, 2026 07:05
Comment thread src/components/AmountForm.tsx Resolved
@bernhardoj

Copy link
Copy Markdown
Contributor

Only iOS is left to be tested; the build keeps failing for me.

@jmgraa

jmgraa commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Any particular reason for that?

@bernhardoj

Copy link
Copy Markdown
Contributor

I get this when running npm run ios

Failed: Building the app
│
■  RockError: Failed to build the project
│      at buildProject (file:///Users/bernhardoj/Documents/dev/freelance/Expensify/node_modules/@rock-js/platform-apple-helpers/dist/src/lib/commands/build/buildProject.js:38:15)
│      at async buildApp (file:///Users/bernhardoj/Documents/dev/freelance/Expensify/node_modules/@rock-js/platform-apple-helpers/dist/src/lib/utils/buildApp.js:68:5)
│      at async Promise.all (index 1)
│      at async createRun (file:///Users/bernhardoj/Documents/dev/freelance/Expensify/node_modules/@rock-js/platform-apple-helpers/dist/src/lib/commands/run/createRun.js:177:70)
│      at async Object.action (file:///Users/bernhardoj/Documents/dev/freelance/Expensify/node_modules/@rock-js/platform-ios/dist/src/lib/platformIOS.js:35:13)
│      at async Command.<anonymous> (file:///Users/bernhardoj/Documents/dev/freelance/Expensify/node_modules/rock/dist/src/lib/cli.js:41:17)
│      at async Command.parseAsync (/Users/bernhardoj/Documents/dev/freelance/Expensify/node_modules/commander/lib/command.js:1092:5)
│      at async cli (file:///Users/bernhardoj/Documents/dev/freelance/Expensify/node_modules/rock/dist/src/lib/cli.js:76:5) {
│    [cause]: "xcodebuild -workspace Expensify.xcworkspace -configuration Debug -scheme 'Expensify Dev' -destination 'id=7818C86B-993B-4023-A5F4-1DDD1E6F4602'"
│  }

Tried running npm run clean then npm run pod-install, but still error.

@bernhardoj

bernhardoj commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
android.mp4
Android: mWeb Chrome
android.mweb.mp4
iOS: HybridApp
ios.mp4
iOS: mWeb Safari
ios.mweb.mp4
MacOS: Chrome / Safari
web.new.mp4

@jmgraa

jmgraa commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

@mountiny can you take a look at / merge that?

@mountiny

mountiny commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Thanks for your patience

@mountiny
mountiny merged commit 4541881 into Expensify:main Sep 9, 2026
34 of 36 checks passed
@OSBotify

OSBotify commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

OSBotify commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.4.75-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 No help site changes are required for this PR, so I did not create a draft docs PR.

This is an internal refactor. It introduces NumericField and NumericEditingController and switches AmountForm's standard text-input mode to use them. Nothing a customer reads or clicks changed:

  • No copy changes. The diff touches no src/languages/* file, so every label, button, tab, and error string is byte-identical.
  • No new setting, page, or flow. All 20 changed files are under src/components/NumericEditingController/, src/components/NumericField/, src/components/AmountForm.tsx, and tests/.
  • No documented behavior changed. The only amount-entry behavior the help site describes is decimal support on workspace rules — docs/articles/new-expensify/workspaces/Workspace-Rules.md:33-36 already says Receipt required amount and Max expense amount support decimals, and Max expense age (Days) is whole numbers only. This PR preserves all of that.
  • The edge-case differences you flagged are caret and normalization internals. Caret position after a forward delete, or how a rejected keystroke restores the last valid value, is not something the help site documents at any level of detail. Documenting it would add noise, not guidance.
What I checked

I searched all of docs/articles for content that could describe this behavior — decimal separators, caret behavior, amount form mechanics, and "Max expense amount". The only real matches were the workspace rules and expense violations articles, which describe what the limits mean, not how the input field behaves while you type. The Expensify Classic matches are for the Classic UI and are untouched by this PR.

I also confirmed the PR is scoped entirely to component internals and tests, with no route, no new Settings entry, and no marketing-approved copy.

Since there is no docs PR, there is nothing to label HelpDot, assign, or mark ready for review. If part 2 of this work (following #98967) adds a user-facing surface or changes copy, ping me on that PR and I'll draft the docs update then.


view run

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/mountiny in version: 9.4.75-3 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 failure ❌
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/mountiny in version: 9.4.75-3 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 failure ❌
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

@jmgraa
jmgraa deleted the jmgraa/NumericField_NumericEditingController branch October 7, 2026 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants