diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index af952613f48f..6daca3d97f22 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -11,6 +11,7 @@ import SelectionListWithModal from '@components/SelectionListWithModal'; import SearchRowSkeleton from '@components/Skeletons/SearchRowSkeleton'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; +import usePrevious from '@hooks/usePrevious'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import {turnOffMobileSelectionMode, turnOnMobileSelectionMode} from '@libs/actions/MobileSelectionMode'; @@ -177,6 +178,16 @@ function Search({queryJSON, policyIDs, isCustomQuery}: SearchProps) { const shouldShowLoadingState = !isOffline && !isDataLoaded; const shouldShowLoadingMoreItems = !shouldShowLoadingState && searchResults?.search?.isLoading && searchResults?.search?.offset > 0; + const isSearchResultsEmpty = !searchResults || SearchUtils.isSearchResultsEmpty(searchResults); + const prevIsSearchResultEmpty = usePrevious(isSearchResultsEmpty); + + useEffect(() => { + if (!isSearchResultsEmpty || prevIsSearchResultEmpty) { + return; + } + turnOffMobileSelectionMode(); + }, [isSearchResultsEmpty, prevIsSearchResultEmpty]); + const toggleTransaction = (item: TransactionListItemType | ReportListItemType) => { if (SearchUtils.isTransactionListItemType(item)) { if (!item.keyForList) {