Skip to content

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
raspi-user:bobphoneentrydropdown
Open

fix for phone entry to ensure if country selected first it remains selected, with unit tests#27
raspi-user wants to merge 1 commit intobsv-blockchain:masterfrom
raspi-user:bobphoneentrydropdown

Conversation

@raspi-user
Copy link
Copy Markdown

@raspi-user raspi-user commented Oct 11, 2025

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:
1C3F3E70-5682-409B-960A-0AEC96A4BB0E

Original code fails the 2 tests for set picked country, while the fixed code passes the same 2 tests:
DD91280E-BA88-4B17-8A22-89F5A9184EDA

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.

1 participant