fix for phone entry to ensure if country selected first it remains selected, with unit tests#27
Open
raspi-user wants to merge 1 commit intobsv-blockchain:masterfrom
Open
Conversation
…lected, with unit tests
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.
This PR fixes a long-standing UX bug where the Country dropdown in PhoneEntry would revert to United States (+1) after the user started typing a phone number. The component now preserves the user’s country selection and correctly emits E.164 values.
What changed:
Sticky country selection
Added a userPickedCountry ref to distinguish between user-chosen country vs. auto-derived country from the incoming value prop.
We only auto-set the country from parsePhoneNumberFromString(value) if the user hasn’t explicitly picked one in the session.
Robust value emission:
Always emit dialCode + digits (E.164 without separators) when the number field changes.
Sanitizes non-digits in the number input.
Validates via libphonenumber-js/min; shows contextual error messages.
Safer defaults
Default country remains US but will not override a user’s selection.
UI
MUI Select change handler marks the selection as user-driven so it persists during further typing or parent prop changes.
Shows UK remains set when phone number entered:

Original code fails the 2 tests for set picked country, while the fixed code passes the same 2 tests:
