diff --git a/src/components/SelectionList/BaseSelectionList.tsx b/src/components/SelectionList/BaseSelectionList.tsx index 6bbe69a1e2c6..ae092b8c2729 100644 --- a/src/components/SelectionList/BaseSelectionList.tsx +++ b/src/components/SelectionList/BaseSelectionList.tsx @@ -86,6 +86,7 @@ function BaseSelectionList( windowSize = 5, updateCellsBatchingPeriod = 50, removeClippedSubviews = true, + shouldDelayFocus = true, }: BaseSelectionListProps, ref: ForwardedRef, ) { @@ -507,27 +508,28 @@ function BaseSelectionList( }; }, [debouncedSelectFocusedOption, shouldDebounceRowSelect]); + /** Function to focus text input */ + const focusTextInput = useCallback(() => { + if (!innerTextInputRef.current) { + return; + } + + innerTextInputRef.current.focus(); + }, []); + /** Focuses the text input when the component comes into focus and after any navigation animations finish. */ useFocusEffect( useCallback(() => { - if (!textInputAutoFocus) { - return; - } - if (shouldShowTextInput) { - focusTimeoutRef.current = setTimeout(() => { - if (!innerTextInputRef.current) { - return; - } - innerTextInputRef.current.focus(); - }, CONST.ANIMATED_TRANSITION); - } - return () => { - if (!focusTimeoutRef.current) { - return; + if (textInputAutoFocus && shouldShowTextInput) { + if (shouldDelayFocus) { + focusTimeoutRef.current = setTimeout(focusTextInput, CONST.ANIMATED_TRANSITION); + } else { + focusTextInput(); } - clearTimeout(focusTimeoutRef.current); - }; - }, [shouldShowTextInput, textInputAutoFocus]), + } + + return () => focusTimeoutRef.current && clearTimeout(focusTimeoutRef.current); + }, [shouldShowTextInput, textInputAutoFocus, shouldDelayFocus, focusTextInput]), ); const prevTextInputValue = usePrevious(textInputValue); diff --git a/src/pages/ChatFinderPage/index.tsx b/src/pages/ChatFinderPage/index.tsx index 5cd26dafef44..0ff04deb09f0 100644 --- a/src/pages/ChatFinderPage/index.tsx +++ b/src/pages/ChatFinderPage/index.tsx @@ -193,6 +193,7 @@ function ChatFinderPage({betas, isSearchingForReports, navigation}: ChatFinderPa showLoadingPlaceholder={!areOptionsInitialized || !isScreenTransitionEnd} footerContent={!isDismissed && ChatFinderPageFooterInstance} isLoadingNewOptions={!!isSearchingForReports} + shouldDelayFocus={false} /> );