1
- import { ChangeEvent , KeyboardEvent , useCallback , useContext , useEffect , useMemo , useRef , useState } from "react" ;
1
+ import {
2
+ ChangeEvent ,
3
+ forwardRef ,
4
+ KeyboardEvent ,
5
+ useCallback ,
6
+ useContext ,
7
+ useEffect ,
8
+ useMemo ,
9
+ useRef ,
10
+ useState
11
+ } from "react" ;
2
12
import useFormInstance from "antd/es/form/hooks/useFormInstance" ;
3
13
import { FormContext } from "antd/es/form/context" ;
4
14
import Select from "antd/es/select" ;
@@ -21,22 +31,22 @@ import {PhoneInputProps, PhoneNumber} from "./types";
21
31
22
32
injectMergedStyles ( ) ;
23
33
24
- const PhoneInput = ( {
25
- value : initialValue = "" ,
26
- country = getDefaultISO2Code ( ) ,
27
- enableSearch = false ,
28
- disableDropdown = false ,
29
- onlyCountries = [ ] ,
30
- excludeCountries = [ ] ,
31
- preferredCountries = [ ] ,
32
- searchNotFound = "No country found" ,
33
- searchPlaceholder = "Search country" ,
34
- onMount : handleMount = ( ) => null ,
35
- onInput : handleInput = ( ) => null ,
36
- onChange : handleChange = ( ) => null ,
37
- onKeyDown : handleKeyDown = ( ) => null ,
38
- ...antInputProps
39
- } : PhoneInputProps ) => {
34
+ const PhoneInput = forwardRef ( ( {
35
+ value : initialValue = "" ,
36
+ country = getDefaultISO2Code ( ) ,
37
+ enableSearch = false ,
38
+ disableDropdown = false ,
39
+ onlyCountries = [ ] ,
40
+ excludeCountries = [ ] ,
41
+ preferredCountries = [ ] ,
42
+ searchNotFound = "No country found" ,
43
+ searchPlaceholder = "Search country" ,
44
+ onMount : handleMount = ( ) => null ,
45
+ onInput : handleInput = ( ) => null ,
46
+ onChange : handleChange = ( ) => null ,
47
+ onKeyDown : handleKeyDown = ( ) => null ,
48
+ ...antInputProps
49
+ } : PhoneInputProps , ref : any ) => {
40
50
const formInstance = useFormInstance ( ) ;
41
51
const formContext = useContext ( FormContext ) ;
42
52
const backRef = useRef < boolean > ( false ) ;
@@ -164,6 +174,7 @@ const PhoneInput = ({
164
174
< div className = "ant-phone-input-wrapper"
165
175
ref = { node => setMinWidth ( node ?. offsetWidth || 0 ) } >
166
176
< Input
177
+ ref = { ref }
167
178
inputMode = "tel"
168
179
value = { value }
169
180
onInput = { onInput }
@@ -174,6 +185,6 @@ const PhoneInput = ({
174
185
/>
175
186
</ div >
176
187
)
177
- }
188
+ } )
178
189
179
190
export default PhoneInput ;
0 commit comments