diff --git a/src/components/SelectionList/BaseSelectionList.tsx b/src/components/SelectionList/BaseSelectionList.tsx index ad69d27e7385..f9186cb4a888 100644 --- a/src/components/SelectionList/BaseSelectionList.tsx +++ b/src/components/SelectionList/BaseSelectionList.tsx @@ -105,6 +105,7 @@ function BaseSelectionList( shouldDelayFocus = true, onArrowFocus = () => {}, shouldUpdateFocusedIndex = false, + shouldResetFocusedIndex = false, onLongPressRow, shouldShowTextInput = !!textInputLabel || !!textInputIconLeft, shouldShowListEmptyContent = true, @@ -666,7 +667,7 @@ function BaseSelectionList( // reseting the currrent page to 1 when the user types something setCurrentPage(1); - updateAndScrollToFocusedIndex(newSelectedIndex); + updateAndScrollToFocusedIndex(shouldResetFocusedIndex ? 0 : newSelectedIndex); }, [ canSelectMultiple, flattenedSections.allOptions.length, @@ -677,6 +678,7 @@ function BaseSelectionList( prevSelectedOptionsLength, prevAllOptionsLength, shouldUpdateFocusedIndex, + shouldResetFocusedIndex, ]); useEffect( diff --git a/src/components/SelectionList/types.ts b/src/components/SelectionList/types.ts index 8e94b2f0069e..72da3ba8646b 100644 --- a/src/components/SelectionList/types.ts +++ b/src/components/SelectionList/types.ts @@ -395,6 +395,9 @@ type BaseSelectionListProps = Partial & { /** Whether to update the focused index on a row select */ shouldUpdateFocusedIndex?: boolean; + /** Whether to reset the focused index to zero */ + shouldResetFocusedIndex?: boolean; + /** Optional callback function triggered upon pressing a checkbox. If undefined and the list displays checkboxes, checkbox interactions are managed by onSelectRow, allowing for pressing anywhere on the list. */ onCheckboxPress?: (item: TItem) => void; diff --git a/src/components/SelectionScreen.tsx b/src/components/SelectionScreen.tsx index 020796085ba4..051e99e1e674 100644 --- a/src/components/SelectionScreen.tsx +++ b/src/components/SelectionScreen.tsx @@ -94,6 +94,9 @@ type SelectionScreenProps = { /** Whether to update the focused index on a row select */ shouldUpdateFocusedIndex?: boolean; + /** Whether to reset the focused index to zero */ + shouldResetFocusedIndex?: boolean; + /** Whether to show the text input */ shouldShowTextInput?: boolean; @@ -134,6 +137,7 @@ function SelectionScreen({ onChangeText, shouldShowTextInput, shouldUpdateFocusedIndex = false, + shouldResetFocusedIndex = false, }: SelectionScreenProps) { const {translate} = useLocalize(); const styles = useThemeStyles(); @@ -179,6 +183,7 @@ function SelectionScreen({ sectionListStyle={!!sections.length && [styles.flexGrow0]} shouldSingleExecuteRowSelect={shouldSingleExecuteRowSelect} shouldUpdateFocusedIndex={shouldUpdateFocusedIndex} + shouldResetFocusedIndex={shouldResetFocusedIndex} isAlternateTextMultilineSupported > mode.isSelected)?.keyForList} + shouldResetFocusedIndex onBackButtonPress={() => Navigation.goBack(ROUTES.WORKSPACE_COMPANY_CARD_DETAILS.getRoute(policyID, cardID, bank))} headerTitleAlreadyTranslated={exportMenuItem?.description} listEmptyContent={listEmptyContent}