@@ -23,15 +23,15 @@ const parsePhoneNumber: ParsePhoneNumber = (value, data, formattedNumber) => {
2323 const countryCodePattern = / \+ \d + / ;
2424 const areaCodePattern = / \( ( \d + ) \) / ;
2525
26- /** Parse the matching partials of the phone number by predefined regex patterns */
26+ /** Parses the matching partials of the phone number by predefined regex patterns */
2727 const countryCodeMatch = formattedNumber ? ( formattedNumber . match ( countryCodePattern ) || [ ] ) : [ ] ;
2828 const areaCodeMatch = formattedNumber ? ( formattedNumber . match ( areaCodePattern ) || [ ] ) : [ ] ;
2929
30- /** Convert the parsed values of the country and area codes to integers if values present */
30+ /** Converts the parsed values of the country and area codes to integers if values present */
3131 const countryCode = countryCodeMatch . length > 0 ? parseInt ( countryCodeMatch [ 0 ] ) : null ;
3232 const areaCode = areaCodeMatch . length > 1 ? parseInt ( areaCodeMatch [ 1 ] ) : null ;
3333
34- /** Parse the phone number by removing the country and area codes from the formatted value */
34+ /** Parses the phone number by removing the country and area codes from the formatted value */
3535 const phoneNumberPattern = new RegExp ( `^${ countryCode } ${ ( areaCode || "" ) } (\\d+)` ) ;
3636 const phoneNumberMatch = value ? ( value . match ( phoneNumberPattern ) || [ ] ) : [ ] ;
3737 const phoneNumber = phoneNumberMatch . length > 1 ? phoneNumberMatch [ 1 ] : null ;
@@ -76,7 +76,7 @@ const PhoneInput = ({
7676 const code = metadata . isoCode as ISO2Code ;
7777
7878 if ( code !== currentCode ) {
79- /** Clear phone number when the country is selected manually */
79+ /** Clears phone number when the country is selected manually */
8080 handleChange ( { ...metadata , areaCode : null , phoneNumber : null } , event ) ;
8181 setCurrentCode ( code ) ;
8282 return ;
@@ -87,6 +87,8 @@ const PhoneInput = ({
8787
8888 const onMount : ReactPhoneOnMount = ( rawValue , { countryCode, ...event } , formattedNumber ) => {
8989 const metadata = parsePhoneNumber ( rawValue , { countryCode} , formattedNumber ) ;
90+ /** Initiates the current country code with the code of initial value */
91+ setCurrentCode ( metadata . isoCode as ISO2Code ) ;
9092 /** Initializes the existing value */
9193 handleChange ( metadata , event ) ;
9294 handleMount ( metadata ) ;
0 commit comments