@@ -31,6 +31,22 @@ function BasePhoneInput({
3131} : PhoneInputProps ) {
3232 const isPlatform = useIsPlatform ( ) ;
3333
34+ // This is to trigger validation on prefill value changes
35+ useEffect ( ( ) => {
36+ if ( ! value ) return ;
37+
38+ const sanitized = value
39+ . trim ( )
40+ . replace ( / [ ^ \d + ] / g, "" )
41+ . replace ( / ^ \+ ? / , "+" ) ;
42+
43+ if ( sanitized === "+" || sanitized === "" ) return ;
44+
45+ if ( value !== sanitized ) {
46+ onChange ( sanitized ) ;
47+ }
48+ } , [ ] ) ;
49+
3450 if ( ! isPlatform ) {
3551 return (
3652 < BasePhoneInputWeb name = { name } className = { className } onChange = { onChange } value = { value } { ...rest } />
@@ -45,12 +61,12 @@ function BasePhoneInput({
4561 disableSearchIcon
4662 country = { defaultCountry }
4763 inputProps = { {
48- name : name ,
64+ name,
4965 required : rest . required ,
5066 placeholder : rest . placeholder ,
5167 } }
52- onChange = { ( value ) => {
53- onChange ( `+${ value } ` ) ;
68+ onChange = { ( val : string ) => {
69+ onChange ( `+${ val } ` ) ;
5470 } }
5571 containerClass = { classNames (
5672 "hover:border-emphasis dark:focus:border-emphasis border-default !bg-default rounded-md border focus-within:outline-none focus-within:ring-2 focus-within:ring-brand-default disabled:cursor-not-allowed" ,
@@ -84,6 +100,7 @@ function BasePhoneInputWeb({
84100 ...rest
85101} : Omit < PhoneInputProps , "defaultCountry" > ) {
86102 const defaultCountry = useDefaultCountry ( ) ;
103+
87104 return (
88105 < PhoneInput
89106 { ...rest }
@@ -92,12 +109,12 @@ function BasePhoneInputWeb({
92109 enableSearch
93110 disableSearchIcon
94111 inputProps = { {
95- name : name ,
112+ name,
96113 required : rest . required ,
97114 placeholder : rest . placeholder ,
98115 } }
99- onChange = { ( value ) => {
100- onChange ( `+${ value } ` ) ;
116+ onChange = { ( val : string ) => {
117+ onChange ( `+${ val } ` ) ;
101118 } }
102119 containerClass = { classNames (
103120 "hover:border-emphasis dark:focus:border-emphasis border-default !bg-default rounded-md border focus-within:outline-none focus-within:ring-2 focus-within:ring-brand-default disabled:cursor-not-allowed" ,
0 commit comments