Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ function BaseSelectionList<TItem extends ListItem>(
isFocused,
});

const clearInputAfterSelect = useCallback(() => {
onChangeText?.('');
}, [onChangeText]);

// eslint-disable-next-line react-hooks/exhaustive-deps
const debouncedOnSelectRow = useCallback(lodashDebounce(onSelectRow, 1000, {leading: true}), [onSelectRow]);

Expand All @@ -285,6 +289,10 @@ function BaseSelectionList<TItem extends ListItem>(
scrollToIndex(Math.max(selectedOptionsCount - 1, 0), true);
}
}

if (shouldShowTextInput) {
clearInputAfterSelect();
}
}

if (shouldDebounceRowSelect) {
Expand Down Expand Up @@ -579,7 +587,7 @@ function BaseSelectionList<TItem extends ListItem>(
[flattenedSections.allOptions, setFocusedIndex, updateAndScrollToFocusedIndex],
);

useImperativeHandle(ref, () => ({scrollAndHighlightItem}), [scrollAndHighlightItem]);
useImperativeHandle(ref, () => ({scrollAndHighlightItem, clearInputAfterSelect}), [scrollAndHighlightItem, clearInputAfterSelect]);

/** Selects row when pressing Enter */
useKeyboardShortcut(CONST.KEYBOARD_SHORTCUTS.ENTER, shouldDebounceRowSelect ? debouncedSelectFocusedOption : selectFocusedOption, {
Expand Down
1 change: 1 addition & 0 deletions src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ type BaseSelectionListProps<TItem extends ListItem> = Partial<ChildrenProps> & {

type SelectionListHandle = {
scrollAndHighlightItem?: (items: string[], timeout: number) => void;
clearInputAfterSelect?: () => void;
};

type ItemLayout = {
Expand Down
8 changes: 6 additions & 2 deletions src/pages/NewChatPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import isEmpty from 'lodash/isEmpty';
import reject from 'lodash/reject';
import React, {useCallback, useEffect, useMemo, useState} from 'react';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {useOnyx} from 'react-native-onyx';
import Button from '@components/Button';
import KeyboardAvoidingView from '@components/KeyboardAvoidingView';
Expand All @@ -11,7 +11,7 @@ import ReferralProgramCTA from '@components/ReferralProgramCTA';
import ScreenWrapper from '@components/ScreenWrapper';
import SelectCircle from '@components/SelectCircle';
import SelectionList from '@components/SelectionList';
import type {ListItem} from '@components/SelectionList/types';
import type {ListItem, SelectionListHandle} from '@components/SelectionList/types';
import UserListItem from '@components/SelectionList/UserListItem';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useDebouncedState from '@hooks/useDebouncedState';
Expand Down Expand Up @@ -128,6 +128,7 @@ function NewChatPage({isGroupChat}: NewChatPageProps) {
const personalData = useCurrentUserPersonalDetails();
const {insets} = useStyledSafeAreaInsets();
const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false});
const selectionListRef = useRef<SelectionListHandle>(null);

const {headerMessage, searchTerm, debouncedSearchTerm, setSearchTerm, selectedOptions, setSelectedOptions, recentReports, personalDetails, userToInvite, areOptionsInitialized} =
useOptions({
Expand Down Expand Up @@ -223,6 +224,8 @@ function NewChatPage({isGroupChat}: NewChatPageProps) {
newSelectedOptions = [...selectedOptions, {...option, isSelected: true, selected: true, reportID: option.reportID ?? ''}];
}

selectionListRef?.current?.clearInputAfterSelect?.();

setSelectedOptions(newSelectedOptions);
}

Expand Down Expand Up @@ -301,6 +304,7 @@ function NewChatPage({isGroupChat}: NewChatPageProps) {
keyboardVerticalOffset={variables.contentHeaderHeight + (insets?.top ?? 0) + variables.tabSelectorButtonHeight + variables.tabSelectorButtonPadding}
>
<SelectionList<OptionsListUtils.Option & ListItem>
ref={selectionListRef}
ListItem={UserListItem}
sections={areOptionsInitialized ? sections : CONST.EMPTY_ARRAY}
textInputValue={searchTerm}
Expand Down