@@ -17,6 +17,7 @@ import {FormContext} from "antd/es/form/context";
1717import { useWatch } from "antd/es/form/Form" ;
1818import version from "antd/es/version" ;
1919import Select from "antd/es/select" ;
20+ import Space from "antd/es/space" ;
2021import Input from "antd/es/input" ;
2122
2223import {
@@ -39,7 +40,8 @@ import {PhoneInputProps, PhoneNumber} from "./types";
3940
4041const [ major , minor , _ ] = version . split ( "." ) . map ( Number ) ;
4142const isV5x = major === 5 ;
42- const isV5x25 = isV5x && minor >= 25 ;
43+ const isV6x = major === 6 ;
44+ const isLatest = isV6x || ( isV5x && minor >= 25 ) ;
4345
4446const PhoneInput = forwardRef ( ( {
4547 value : initialValue = "" ,
@@ -227,9 +229,10 @@ const PhoneInput = forwardRef(({
227229 inputRef . current . input . focus ( ) ;
228230 } }
229231 optionLabelProp = "label"
230- { ...( isV5x ? { onOpenChange : onDropdownVisibleChange } : { onDropdownVisibleChange} ) }
231- { ...( isV5x25 ? { styles : { popup : { root : { minWidth} } } } : { dropdownStyle : { minWidth} } ) }
232- { ...( { [ isV5x ? "popupRender" : "dropdownRender" ] : ( menu : any ) => (
232+ style = { { width : 42 + ( enableArrow ? 24 : 0 ) } }
233+ { ...( ( isV5x || isV6x ) ? { onOpenChange : onDropdownVisibleChange } : { onDropdownVisibleChange} ) }
234+ { ...( isLatest ? { styles : { popup : { root : { minWidth} } } } : { dropdownStyle : { minWidth} } ) }
235+ { ...( { [ ( isV5x || isV6x ) ? "popupRender" : "dropdownRender" ] : ( menu : any ) => (
233236 < div className = { `${ prefixCls } -phone-input-search-wrapper` } >
234237 { enableSearch && (
235238 < Input
@@ -250,7 +253,7 @@ const PhoneInput = forwardRef(({
250253 value = { selectValue }
251254 style = { { display : "none" } }
252255 key = { `${ countryCode } _default` }
253- label = { < div style = { { display : "flex" } } >
256+ label = { < div style = { { display : "flex" , alignItems : "center" } } >
254257 < div className = { `flag ${ countryCode } ${ useSVG ? "svg" : "" } ` } />
255258 { suffixIcon }
256259 </ div > }
@@ -261,7 +264,7 @@ const PhoneInput = forwardRef(({
261264 < Select . Option
262265 value = { iso + dial }
263266 key = { `${ iso } _${ mask } ` }
264- label = { < div style = { { display : "flex" } } >
267+ label = { < div style = { { display : "flex" , alignItems : "center" } } >
265268 < div className = { `flag ${ iso } ${ useSVG ? "svg" : "" } ` } />
266269 { suffixIcon }
267270 </ div > }
@@ -273,22 +276,24 @@ const PhoneInput = forwardRef(({
273276 )
274277 } ) }
275278 </ Select >
276- ) , [ selectValue , suffixIcon , countryCode , query , disabled , disableParentheses , disableDropdown , onDropdownVisibleChange , minWidth , searchNotFound , countries , countriesList , setFieldValue , setValue , prefixCls , enableSearch , searchPlaceholder , useSVG ] )
279+ ) , [ selectValue , suffixIcon , countryCode , query , disabled , disableParentheses , disableDropdown , onDropdownVisibleChange , minWidth , searchNotFound , countries , countriesList , setFieldValue , setValue , prefixCls , enableSearch , enableArrow , searchPlaceholder , useSVG ] )
277280
278281 return (
279282 < div className = { `${ prefixCls } -phone-input-wrapper` }
280283 ref = { node => setMinWidth ( node ?. offsetWidth || 0 ) } >
281- < Input
282- ref = { ref }
283- inputMode = "tel"
284- value = { value }
285- onInput = { onInput }
286- onChange = { onChange }
287- onKeyDown = { onKeyDown }
288- addonBefore = { dropdownRender ( countriesSelect ) }
289- disabled = { disabled }
290- { ...antInputProps }
291- />
284+ < Space . Compact >
285+ { dropdownRender ( countriesSelect ) }
286+ < Input
287+ ref = { ref }
288+ inputMode = "tel"
289+ value = { value }
290+ onInput = { onInput }
291+ onChange = { onChange }
292+ onKeyDown = { onKeyDown }
293+ disabled = { disabled }
294+ { ...antInputProps }
295+ />
296+ </ Space . Compact >
292297 </ div >
293298 )
294299} )
0 commit comments