@@ -143,20 +143,21 @@ export default function AddressInput(props: AddressInputProps) {
143143 props . onAddressSelected ( item . toText ( ) , item . point )
144144 }
145145 }
146- // Enter: focus next address input, or blur if last
147- if ( event . key === 'Enter' ) {
148- const next = document
149- . querySelector < HTMLElement > ( '[data-search-box]' ) !
150- . querySelectorAll < HTMLInputElement > ( 'input[type="text"]' ) [ props . index + 1 ]
151- if ( next ) next . focus ( )
152- else searchInput . current ! . blur ( )
153- }
146+ if ( event . key === 'Enter' ) focusNextOrBlur ( )
154147 break
155148 }
156149 } ,
157150 [ autocompleteItems , highlightedResult ] ,
158151 )
159152
153+ const focusNextOrBlur = ( ) => {
154+ const next = document
155+ . querySelector < HTMLElement > ( '[data-search-box]' ) !
156+ . querySelectorAll < HTMLInputElement > ( 'input[type="text"]' ) [ props . index + 1 ]
157+ if ( next ) next . focus ( )
158+ else searchInput . current ! . blur ( )
159+ }
160+
160161 // the "fullscreen" css is only defined for smallscreen
161162 const containerClass = hasFocus ? styles . fullscreen : ''
162163 const type = props . point . type
@@ -271,7 +272,7 @@ export default function AddressInput(props: AddressInputProps) {
271272 handlePoiSearch ( poiSearch , item . result , props . map )
272273 setText ( item . result . text ( item . result . poi ) )
273274 }
274- searchInput . current ! . blur ( ) // see also AutocompleteEntry->onMouseDown
275+ focusNextOrBlur ( )
275276 } }
276277 />
277278 </ ResponsiveAutocomplete >
0 commit comments