@@ -15,6 +15,7 @@ import useFormInstance from "antd/es/form/hooks/useFormInstance";
1515import { ConfigContext } from "antd/es/config-provider" ;
1616import { FormContext } from "antd/es/form/context" ;
1717import { useWatch } from "antd/es/form/Form" ;
18+ import version from "antd/es/version" ;
1819import Select from "antd/es/select" ;
1920import Input from "antd/es/input" ;
2021
@@ -36,9 +37,14 @@ import locale from "./locale";
3637import { injectMergedStyles } from "./styles" ;
3738import { PhoneInputProps , PhoneNumber } from "./types" ;
3839
40+ const [ major , minor , _ ] = version . split ( "." ) . map ( Number ) ;
41+ const isV5x = major === 5 ;
42+ const isV5x25 = isV5x && minor >= 25 ;
43+
3944const PhoneInput = forwardRef ( ( {
4045 value : initialValue = "" ,
4146 country = getDefaultISO2Code ( ) ,
47+ useSVG = false ,
4248 distinct = false ,
4349 disabled = false ,
4450 enableArrow = false ,
@@ -221,9 +227,9 @@ const PhoneInput = forwardRef(({
221227 inputRef . current . input . focus ( ) ;
222228 } }
223229 optionLabelProp = "label"
224- dropdownStyle = { { minWidth } }
225- onDropdownVisibleChange = { onDropdownVisibleChange }
226- dropdownRender = { ( menu ) => (
230+ { ... ( isV5x ? { onOpenChange : onDropdownVisibleChange } : { onDropdownVisibleChange } ) }
231+ { ... ( isV5x25 ? { styles : { popup : { root : { minWidth } } } } : { dropdownStyle : { minWidth } } ) }
232+ { ... ( { [ isV5x ? "popupRender" : "dropdownRender" ] : ( menu : any ) => (
227233 < div className = { `${ prefixCls } -phone-input-search-wrapper` } >
228234 { enableSearch && (
229235 < Input
@@ -237,15 +243,15 @@ const PhoneInput = forwardRef(({
237243 < div className = "ant-select-item-empty" > { searchNotFound } </ div >
238244 ) }
239245 </ div >
240- ) }
246+ ) } ) }
241247 >
242248 < Select . Option
243249 children = { null }
244250 value = { selectValue }
245251 style = { { display : "none" } }
246252 key = { `${ countryCode } _default` }
247253 label = { < div style = { { display : "flex" } } >
248- < div className = { `flag ${ countryCode } ` } />
254+ < div className = { `flag ${ countryCode } ${ useSVG ? "svg" : "" } ` } />
249255 { suffixIcon }
250256 </ div > }
251257 />
@@ -256,18 +262,18 @@ const PhoneInput = forwardRef(({
256262 value = { iso + dial }
257263 key = { `${ iso } _${ mask } ` }
258264 label = { < div style = { { display : "flex" } } >
259- < div className = { `flag ${ iso } ` } />
265+ < div className = { `flag ${ iso } ${ useSVG ? "svg" : "" } ` } />
260266 { suffixIcon }
261267 </ div > }
262268 children = { < div className = { `${ prefixCls } -phone-input-select-item` } >
263- < div className = { `flag ${ iso } ` } />
269+ < div className = { `flag ${ iso } ${ useSVG ? "svg" : "" } ` } />
264270 { countries [ name ] } { displayFormat ( mask ) }
265271 </ div > }
266272 />
267273 )
268274 } ) }
269275 </ Select >
270- ) , [ selectValue , suffixIcon , countryCode , query , disabled , disableParentheses , disableDropdown , onDropdownVisibleChange , minWidth , searchNotFound , countries , countriesList , setFieldValue , setValue , prefixCls , enableSearch , searchPlaceholder ] )
276+ ) , [ selectValue , suffixIcon , countryCode , query , disabled , disableParentheses , disableDropdown , onDropdownVisibleChange , minWidth , searchNotFound , countries , countriesList , setFieldValue , setValue , prefixCls , enableSearch , searchPlaceholder , useSVG ] )
271277
272278 return (
273279 < div className = { `${ prefixCls } -phone-input-wrapper` }
0 commit comments