-
Notifications
You must be signed in to change notification settings - Fork 1
Fix getDerivedStateFromProps to handle simultaneous allowNegative and format prop changes #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
There is no change log for this pull request yet. |
… format prop changes Co-authored-by: ericblade <1451847+ericblade@users.noreply.github.com>
Co-authored-by: ericblade <1451847+ericblade@users.noreply.github.com>
Co-authored-by: ericblade <1451847+ericblade@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a bug in getDerivedStateFromProps where simultaneous changes to allowNegative and format props (like prefix, suffix, or separators) would result in negative values not being converted to positive when allowNegative is disabled. The fix unifies the handling of format changes and allowNegative changes into a single code path, ensuring both are processed correctly.
Key changes:
- Unified prop change handling by including
allowNegativeChangedin theformatChangedcondition - Added value conversion logic that checks if a negative value needs to be converted to positive before applying format changes
- Added comprehensive test coverage for the simultaneous prop change scenario
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/base.spec.ts | Adds test case validating that disabling allowNegative while simultaneously changing the prefix correctly converts negative values to positive and applies the new prefix |
| src/index.tsx | Refactors getDerivedStateFromProps to handle allowNegative changes within the unified format change handler, preventing the early return issue that bypassed negative-to-positive value conversion |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sequential if-statements with early returns in
getDerivedStateFromPropscaused theallowNegativechange handler to be bypassed when format props also changed simultaneously, leaving negative values unconverted to positive.Changes
allowNegativeChangedin theformatChangedcondition so both are handled in a single code pathallowNegativeandprefixchangesExample
When both
allowNegativeandprefixchange (e.g., user unchecks "Allow negative" and changes prefix from "$" to "€"), the value-50.00now correctly becomes€50.00instead of remaining€-50.00.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.