Skip to content

Commit 902272e

Browse files
authored
Merge pull request #56948 from software-mansion-labs/289Adam289/56038-fix-search-autocomplete-list-navigation
Fix SearchAutocompleteList arrow keys navigation
2 parents b1e5656 + f7d329e commit 902272e

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

src/components/Search/SearchAutocompleteList.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ type SearchAutocompleteListProps = {
6767

6868
/** Callback to call when the list of autocomplete substitutions should be updated */
6969
updateAutocompleteSubstitutions: (item: SearchQueryItem) => void;
70+
71+
/** Whether to subscribe to KeyboardShortcut arrow keys events */
72+
shouldSubscribeToArrowKeyEvents?: boolean;
7073
};
7174

7275
const defaultListOptions = {
@@ -118,7 +121,15 @@ function SearchRouterItem(props: UserListItemProps<OptionData> | SearchQueryList
118121
}
119122

120123
function SearchAutocompleteList(
121-
{autocompleteQueryValue, searchQueryItem, getAdditionalSections, onListItemPress, setTextQuery, updateAutocompleteSubstitutions}: SearchAutocompleteListProps,
124+
{
125+
autocompleteQueryValue,
126+
searchQueryItem,
127+
getAdditionalSections,
128+
onListItemPress,
129+
setTextQuery,
130+
updateAutocompleteSubstitutions,
131+
shouldSubscribeToArrowKeyEvents,
132+
}: SearchAutocompleteListProps,
122133
ref: ForwardedRef<SelectionListHandle>,
123134
) {
124135
const styles = useThemeStyles();
@@ -490,6 +501,7 @@ function SearchAutocompleteList(
490501
ref={ref}
491502
initiallyFocusedOptionKey={!shouldUseNarrowLayout ? styledRecentReports.at(0)?.keyForList : undefined}
492503
shouldScrollToFocusedIndex={!isInitialRender}
504+
shouldSubscribeToArrowKeyEvents={shouldSubscribeToArrowKeyEvents}
493505
/>
494506
);
495507
}

src/components/Search/SearchPageHeader/SearchPageHeaderInput.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ function SearchPageHeaderInput({
342342
setTextQuery={setTextAndUpdateSelection}
343343
updateAutocompleteSubstitutions={updateAutocompleteSubstitutions}
344344
ref={listRef}
345+
shouldSubscribeToArrowKeyEvents={isAutocompleteListVisible}
345346
/>
346347
</View>
347348
</View>

src/components/SelectionList/BaseSelectionList.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ function BaseSelectionList<TItem extends ListItem>(
125125
initialNumToRender = 12,
126126
listItemTitleContainerStyles,
127127
isScreenFocused = false,
128+
shouldSubscribeToArrowKeyEvents = true,
128129
}: BaseSelectionListProps<TItem>,
129130
ref: ForwardedRef<SelectionListHandle>,
130131
) {
@@ -337,7 +338,7 @@ function BaseSelectionList<TItem extends ListItem>(
337338
initialFocusedIndex: flattenedSections.allOptions.findIndex((option) => option.keyForList === initiallyFocusedOptionKey),
338339
maxIndex: Math.min(flattenedSections.allOptions.length - 1, CONST.MAX_SELECTION_LIST_PAGE_LENGTH * currentPage - 1),
339340
disabledIndexes: disabledArrowKeyIndexes,
340-
isActive: isFocused,
341+
isActive: shouldSubscribeToArrowKeyEvents && isFocused,
341342
onFocusedIndexChange: (index: number) => {
342343
const focusedItem = flattenedSections.allOptions.at(index);
343344
if (focusedItem) {

src/components/SelectionList/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,9 @@ type BaseSelectionListProps<TItem extends ListItem> = Partial<ChildrenProps> & {
523523
/** Whether to prevent default focusing of options and focus the textinput when selecting an option */
524524
shouldPreventDefaultFocusOnSelectRow?: boolean;
525525

526+
/** Whether to subscribe to KeyboardShortcut arrow keys events */
527+
shouldSubscribeToArrowKeyEvents?: boolean;
528+
526529
/** Custom content to display in the header */
527530
headerContent?: ReactNode;
528531

0 commit comments

Comments
 (0)