Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5191,7 +5191,7 @@ const CONST = {
* The maximum count of items per page for SelectionList.
* When paginate, it multiplies by page number.
*/
MAX_SELECTION_LIST_PAGE_LENGTH: 500,
MAX_SELECTION_LIST_PAGE_LENGTH: 50,

/**
* Bank account names
Expand Down
33 changes: 32 additions & 1 deletion src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,35 @@ function BaseSelectionList<TItem extends ListItem>(
return canShowProductTrainingTooltip && isFocused;
}, [canShowProductTrainingTooltip, isFocused]);

// Calculate initial page count so selected item is loaded
const initialPageCount = useMemo(() => {
if (canSelectMultiple || sections.length === 0) {
return 1;
}

let currentIndex = 0;
for (const section of sections) {
if (section.data) {
for (const item of section.data) {
if (isItemSelected(item)) {
return Math.floor(currentIndex / CONST.MAX_SELECTION_LIST_PAGE_LENGTH) + 1;
}
currentIndex++;
}
}
}

return 1;
}, [sections, canSelectMultiple, isItemSelected]);

useEffect(() => {
if (initialPageCount < 1) {
return;
}

setCurrentPage(initialPageCount);
}, [initialPageCount]);

/**
* Iterates through the sections and items inside each section, and builds 4 arrays along the way:
* - `allOptions`: Contains all the items in the list, flattened, regardless of section
Expand Down Expand Up @@ -777,7 +806,9 @@ function BaseSelectionList<TItem extends ListItem>(
: 0;

// Reset the current page to 1 when the user types something
setCurrentPage(1);
if (prevTextInputValue !== textInputValue) {
setCurrentPage(1);
}

updateAndScrollToFocusedIndex(newSelectedIndex);
}, [
Expand Down
Loading