Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Initial focus in WorkspaceCompanyCardAccountSelectCardPage #53418

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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/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 @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@waterim This function will not be executed because an early return in line 657

(prevTextInputValue === textInputValue && flattenedSections.selectedOptions.length === prevSelectedOptionsLength) will return true

}, [
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
Loading