Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/components/Search/SearchAutocompleteInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type SearchAutocompleteInputProps = {

/** Reference to the outer element */
ref?: ForwardedRef<BaseTextInputRef>;
} & Pick<TextInputProps, 'caretHidden' | 'autoFocus' | 'selection'>;
} & Pick<TextInputProps, 'caretHidden' | 'autoFocus' | 'selection' | 'onKeyPress'>;

function SearchAutocompleteInput({
value,
Expand All @@ -94,6 +94,7 @@ function SearchAutocompleteInput({
isSearchingForReports,
selection,
substitutionMap,
onKeyPress,
ref,
}: SearchAutocompleteInputProps) {
const styles = useThemeStyles();
Expand Down Expand Up @@ -223,6 +224,7 @@ function SearchAutocompleteInput({

onBlur?.();
}}
onKeyPress={onKeyPress}
isLoading={isSearchingForReports}
ref={(element) => {
if (!ref) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {accountIDSelector} from '@selectors/Session';
import {deepEqual} from 'fast-equals';
import isEmpty from 'lodash/isEmpty';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import type {TextInputKeyPressEvent} from 'react-native';
import {View} from 'react-native';
import Animated from 'react-native-reanimated';
import {usePersonalDetails} from '@components/OnyxListItemProvider';
Expand Down Expand Up @@ -131,6 +132,15 @@ function SearchPageHeaderInput({queryJSON, searchRouterListVisible, hideSearchRo
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const handleKeyPress = useCallback((e: TextInputKeyPressEvent) => {
const keyEvent = e as unknown as KeyboardEvent;

if (keyEvent.key === CONST.KEYBOARD_SHORTCUTS.ESCAPE.shortcutKey && textInputRef.current?.isFocused()) {
keyEvent.preventDefault();
textInputRef.current.blur();
}
}, []);

const handleSearchAction = useCallback(
(value: string) => {
// Skip calling handleSearch on the initial mount
Expand Down Expand Up @@ -377,6 +387,7 @@ function SearchPageHeaderInput({queryJSON, searchRouterListVisible, hideSearchRo
wrapperFocusedStyle={styles.searchAutocompleteInputResultsFocused}
autocompleteListRef={listRef}
ref={textInputRef}
onKeyPress={handleKeyPress}
/>
</Animated.View>
{showPopupButton && (
Expand Down Expand Up @@ -457,6 +468,7 @@ function SearchPageHeaderInput({queryJSON, searchRouterListVisible, hideSearchRo
ref={textInputRef}
selection={selection}
substitutionMap={autocompleteSubstitutions}
onKeyPress={handleKeyPress}
/>
</View>
{isAutocompleteListVisible && (
Expand Down
Loading