Skip to content
Closed
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
6 changes: 4 additions & 2 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function BaseSelectionList<TItem extends ListItem>(
shouldDelayFocus = true,
onArrowFocus = () => {},
shouldUpdateFocusedIndex = false,
shouldResetFocusedIndex = false,
onLongPressRow,
shouldShowTextInput = !!textInputLabel || !!textInputIconLeft,
shouldShowListEmptyContent = true,
Expand Down Expand Up @@ -649,7 +650,7 @@ function BaseSelectionList<TItem extends ListItem>(
useEffect(() => {
// Avoid changing focus if the textInputValue remains unchanged.
if (
(prevTextInputValue === textInputValue && flattenedSections.selectedOptions.length === prevSelectedOptionsLength) ||
(prevTextInputValue === textInputValue && flattenedSections.selectedOptions.length === prevSelectedOptionsLength && !shouldResetFocusedIndex) ||
flattenedSections.allOptions.length === 0 ||
shouldUpdateFocusedIndex
) {
Expand All @@ -666,7 +667,7 @@ function BaseSelectionList<TItem extends ListItem>(
// reseting the currrent page to 1 when the user types something
setCurrentPage(1);

updateAndScrollToFocusedIndex(newSelectedIndex);
updateAndScrollToFocusedIndex(shouldResetFocusedIndex ? 0 : newSelectedIndex);
Comment thread
waterim marked this conversation as resolved.
Resolved
}, [
canSelectMultiple,
flattenedSections.allOptions.length,
Expand All @@ -677,6 +678,7 @@ function BaseSelectionList<TItem extends ListItem>(
prevSelectedOptionsLength,
prevAllOptionsLength,
shouldUpdateFocusedIndex,
shouldResetFocusedIndex,
]);

useEffect(
Expand Down
3 changes: 3 additions & 0 deletions src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ type BaseSelectionListProps<TItem extends ListItem> = Partial<ChildrenProps> & {
/** 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;

Expand Down
5 changes: 5 additions & 0 deletions src/components/SelectionScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ type SelectionScreenProps<T = string> = {
/** 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;

Expand Down Expand Up @@ -134,6 +137,7 @@ function SelectionScreen<T = string>({
onChangeText,
shouldShowTextInput,
shouldUpdateFocusedIndex = false,
shouldResetFocusedIndex = false,
}: SelectionScreenProps<T>) {
const {translate} = useLocalize();
const styles = useThemeStyles();
Expand Down Expand Up @@ -179,6 +183,7 @@ function SelectionScreen<T = string>({
sectionListStyle={!!sections.length && [styles.flexGrow0]}
shouldSingleExecuteRowSelect={shouldSingleExecuteRowSelect}
shouldUpdateFocusedIndex={shouldUpdateFocusedIndex}
shouldResetFocusedIndex={shouldResetFocusedIndex}
isAlternateTextMultilineSupported
>
<ErrorMessageRow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function WorkspaceCompanyCardAccountSelectCardPage({route}: WorkspaceCompanyCard
onChangeText={setSearchText}
onSelectRow={updateExportAccount}
initiallyFocusedOptionKey={exportMenuItem?.data?.find((mode) => mode.isSelected)?.keyForList}
shouldResetFocusedIndex
onBackButtonPress={() => Navigation.goBack(ROUTES.WORKSPACE_COMPANY_CARD_DETAILS.getRoute(policyID, cardID, bank))}
headerTitleAlreadyTranslated={exportMenuItem?.description}
listEmptyContent={listEmptyContent}
Expand Down