diff --git a/src/components/Search/SearchAutocompleteList.tsx b/src/components/Search/SearchAutocompleteList.tsx index 3fc9f7a6a4159..fcfd33be2f839 100644 --- a/src/components/Search/SearchAutocompleteList.tsx +++ b/src/components/Search/SearchAutocompleteList.tsx @@ -5,6 +5,7 @@ import {useOnyx} from 'react-native-onyx'; import * as Expensicons from '@components/Icon/Expensicons'; import {usePersonalDetails} from '@components/OnyxProvider'; import {useOptionsList} from '@components/OptionListContextProvider'; +import type {AnimatedTextInputRef} from '@components/RNTextInput'; import SelectionList from '@components/SelectionList'; import type {SearchQueryItem, SearchQueryListItemProps} from '@components/SelectionList/Search/SearchQueryListItem'; import SearchQueryListItem, {isSearchQueryItem} from '@components/SelectionList/Search/SearchQueryListItem'; @@ -76,6 +77,9 @@ type SearchAutocompleteListProps = { /** Callback to highlight (e.g. scroll to) the first matched item in the list. */ onHighlightFirstItem?: () => void; + + /** Ref for textInput */ + textInputRef?: React.RefObject; }; const defaultListOptions = { @@ -134,8 +138,9 @@ function SearchAutocompleteList( onListItemPress, setTextQuery, updateAutocompleteSubstitutions, - shouldSubscribeToArrowKeyEvents, + shouldSubscribeToArrowKeyEvents = true, onHighlightFirstItem, + textInputRef, }: SearchAutocompleteListProps, ref: ForwardedRef, ) { @@ -582,6 +587,9 @@ function SearchAutocompleteList( onLayout={() => { setPerformanceTimersEnd(); setIsInitialRender(false); + if (!!textInputRef?.current && ref && 'current' in ref) { + ref.current?.updateExternalTextInputFocus?.(textInputRef.current.isFocused()); + } }} showScrollIndicator={!shouldUseNarrowLayout} sectionTitleStyles={styles.mhn2} diff --git a/src/components/Search/SearchRouter/SearchRouter.tsx b/src/components/Search/SearchRouter/SearchRouter.tsx index e355ba2fbeffe..748946f6982a7 100644 --- a/src/components/Search/SearchRouter/SearchRouter.tsx +++ b/src/components/Search/SearchRouter/SearchRouter.tsx @@ -362,6 +362,7 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla updateAutocompleteSubstitutions={updateAutocompleteSubstitutions} onHighlightFirstItem={() => listRef.current?.updateAndScrollToFocusedIndex(1)} ref={listRef} + textInputRef={textInputRef} /> )}