Skip to content

Commit f7bf950

Browse files
authored
Merge pull request #4 from adsign/ui-fixes
UI fixes
2 parents c70d9e5 + 4e0a4f0 commit f7bf950

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

dev/app/my-route/route.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/ui/Field/hooks.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,22 @@ export function usePhoneNumberField({
6868
// Prevent re-initializing the phone input more than once
6969
const isInitializedRef = useRef<boolean>(false);
7070

71-
const [regionCode, setRegionCode] = useState<RegionCode>(defaultRegionCode || allowedRegionCodes?.[0] || 'US');
72-
const [phoneNumberInputValue, setPhoneNumberInputValue] = useState<string>('');
73-
7471
// Value can be either string or object based on afterRead hook, so always extract E.164 string to avoid issues
7572
const e164Value = extractE164FromValue(value);
7673

74+
const determineInitialRegionCode = () => {
75+
if (e164Value) {
76+
const parsedPhoneNumber = parseE164ToNationalFormat(e164Value);
77+
if (parsedPhoneNumber?.regionCode) {
78+
return parsedPhoneNumber.regionCode;
79+
}
80+
}
81+
return defaultRegionCode || allowedRegionCodes?.[0] || 'US';
82+
};
83+
84+
const [regionCode, setRegionCode] = useState<RegionCode>(determineInitialRegionCode);
85+
const [phoneNumberInputValue, setPhoneNumberInputValue] = useState<string>('');
86+
7787
const filteredCountryOptions = useMemo(() => {
7888
const regions = allowedRegionCodes?.length ? allowedRegionCodes : countries.map((country) => country.regionCode);
7989
return countryOptions.filter((option) => regions.includes(option.value as RegionCode));

0 commit comments

Comments
 (0)