@@ -133,6 +133,7 @@ const PhoneInput = forwardRef(({
133133 const phoneMetadata = parsePhoneNumber ( formattedNumber , countriesList ) ;
134134 setCountryCode ( phoneMetadata . isoCode as any ) ;
135135 setValue ( formattedNumber ) ;
136+ setQuery ( "" ) ;
136137 handleChange ( { ...phoneMetadata , valid : ( strict : boolean ) => checkValidity ( phoneMetadata , strict ) } , event ) ;
137138 } , [ countriesList , handleChange , pattern , setValue ] )
138139
@@ -183,6 +184,18 @@ const PhoneInput = forwardRef(({
183184 setValue ( formattedNumber ) ;
184185 } , [ countriesList , metadata , onMount , pattern , setValue , value ] )
185186
187+ const suffixIcon = useMemo ( ( ) => {
188+ return enableArrow && (
189+ < span role = "img" className = "anticon" style = { { paddingLeft : 8 } } >
190+ < svg className = "icon" viewBox = "0 0 1024 1024"
191+ focusable = "false" fill = "currentColor" width = "16" height = "18" >
192+ < path
193+ d = "M848 368a48 48 0 0 0-81.312-34.544l-0.016-0.016-254.784 254.784-251.488-251.488a48 48 0 1 0-71.04 64.464l-0.128 0.128 288 288 0.016-0.016a47.84 47.84 0 0 0 34.544 14.688h0.224a47.84 47.84 0 0 0 34.544-14.688l0.016 0.016 288-288-0.016-0.016c8.32-8.624 13.44-20.368 13.44-33.312z" />
194+ </ svg >
195+ </ span >
196+ ) ;
197+ } , [ enableArrow ] )
198+
186199 const countriesSelect = useMemo ( ( ) => (
187200 < Select
188201 suffixIcon = { null }
@@ -206,7 +219,6 @@ const PhoneInput = forwardRef(({
206219 } }
207220 optionLabelProp = "label"
208221 dropdownStyle = { { minWidth} }
209- notFoundContent = { searchNotFound }
210222 onDropdownVisibleChange = { onDropdownVisibleChange }
211223 dropdownRender = { ( menu ) => (
212224 < div className = { `${ prefixCls } -phone-input-search-wrapper` } >
@@ -218,10 +230,22 @@ const PhoneInput = forwardRef(({
218230 onInput = { ( { target} : any ) => setQuery ( target . value ) }
219231 />
220232 ) }
221- { menu }
233+ { countriesList . length ? menu : (
234+ < div className = "ant-select-item-empty" > { searchNotFound } </ div >
235+ ) }
222236 </ div >
223237 ) }
224238 >
239+ < Select . Option
240+ children = { null }
241+ value = { selectValue }
242+ style = { { display : "none" } }
243+ key = { `${ countryCode } _default` }
244+ label = { < >
245+ < div className = { `flag ${ countryCode } ` } />
246+ { suffixIcon }
247+ </ > }
248+ />
225249 { countriesList . map ( ( [ iso , name , dial , pattern ] ) => {
226250 const mask = disableParentheses ? pattern . replace ( / [ ( ) ] / g, "" ) : pattern ;
227251 return (
@@ -230,15 +254,7 @@ const PhoneInput = forwardRef(({
230254 key = { `${ iso } _${ mask } ` }
231255 label = { < >
232256 < div className = { `flag ${ iso } ` } />
233- { enableArrow && (
234- < span role = "img" className = "anticon" style = { { paddingLeft : 8 } } >
235- < svg className = "icon" viewBox = "0 0 1024 1024"
236- focusable = "false" fill = "currentColor" width = "16" height = "18" >
237- < path
238- d = "M848 368a48 48 0 0 0-81.312-34.544l-0.016-0.016-254.784 254.784-251.488-251.488a48 48 0 1 0-71.04 64.464l-0.128 0.128 288 288 0.016-0.016a47.84 47.84 0 0 0 34.544 14.688h0.224a47.84 47.84 0 0 0 34.544-14.688l0.016 0.016 288-288-0.016-0.016c8.32-8.624 13.44-20.368 13.44-33.312z" />
239- </ svg >
240- </ span >
241- ) }
257+ { suffixIcon }
242258 </ > }
243259 children = { < div className = { `${ prefixCls } -phone-input-select-item` } >
244260 < div className = { `flag ${ iso } ` } />
@@ -248,7 +264,7 @@ const PhoneInput = forwardRef(({
248264 )
249265 } ) }
250266 </ Select >
251- ) , [ selectValue , query , enableArrow , disabled , disableParentheses , disableDropdown , onDropdownVisibleChange , minWidth , searchNotFound , countries , countriesList , setFieldValue , setValue , prefixCls , enableSearch , searchPlaceholder ] )
267+ ) , [ selectValue , suffixIcon , countryCode , query , disabled , disableParentheses , disableDropdown , onDropdownVisibleChange , minWidth , searchNotFound , countries , countriesList , setFieldValue , setValue , prefixCls , enableSearch , searchPlaceholder ] )
252268
253269 return (
254270 < div className = { `${ prefixCls } -phone-input-wrapper` }
0 commit comments