Fix/numberfield format options input reset#9905
Open
Wonchang0314 wants to merge 2 commits intoadobe:mainfrom
Open
Fix/numberfield format options input reset#9905Wonchang0314 wants to merge 2 commits intoadobe:mainfrom
Wonchang0314 wants to merge 2 commits intoadobe:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1893
Related to #9899
Summary
When formatOptions is passed as an inline object literal (e.g. formatOptions={{ style: 'currency',
currency: 'USD' }}), every parent re-render creates a new object reference. This caused
useNumberFieldState to detect a "change" in formatOptions and overwrite the current inputValue with
the last committed number value — resetting whatever the user was typing mid-input.
This fix stabilizes the formatOptions reference inside useNumberFieldState using a useRef and a
shallow equality check. If the new formatOptions has the same key-value pairs as the previous one,
the old reference is reused, preventing a spurious inputValue reset. I though this approach is appropriate
because all values in Intl.NumberFormatOptions are primitives (strings, numbers, booleans), so
shallow equality is equivalent to deep equality.
✅ Pull Request Checklist:
📝 Test Instructions:
yarn jest packages/react-aria-components/test/NumberField.test.js
yarn jest packages/@adobe/react-spectrum/test/numberfield/NumberField.test.js
- "does not reset input value when parent re-renders with same formatOptions content" — a parent
component with its own state re-renders while formatOptions is an inline object literal; the typed
value must be preserved.
- "does not reset input during typing when re-rendered with same formatOptions content" — same
scenario via the rerender helper.
}} as an inline literal inside a component that re-renders on some other state change. Type a value
without committing (no blur/Enter) and trigger the parent re-render — the typed value should no
longer be reset.
🧢 Your Project: