Skip to content

Commit f813f87

Browse files
fix: Hide new pageIndex logic behind flag (#103)
1 parent b6007dd commit f813f87

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/__tests__/operations/paginate.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ test('displays an out of range page', () => {
9393
items: processed,
9494
pagesCount,
9595
actualPageIndex,
96-
} = processItems(items, { currentPageIndex: 3 }, { pagination: {} });
96+
} = processItems(items, { currentPageIndex: 3 }, { pagination: { allowPageOutOfRange: true } });
9797
expect(actualPageIndex).toEqual(3);
9898
expect(pagesCount).toEqual(2);
9999
expect(processed).toHaveLength(0);

src/interfaces.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface UseCollectionOptions<T> {
4444
freeTextFiltering?: PropertyFilterFreeTextFiltering;
4545
};
4646
sorting?: { defaultState?: SortingState<T> };
47-
pagination?: { defaultPage?: number; pageSize?: number };
47+
pagination?: { defaultPage?: number; pageSize?: number; allowPageOutOfRange?: boolean };
4848
selection?: {
4949
defaultSelectedItems?: ReadonlyArray<T>;
5050
keepSelection?: boolean;

src/operations/pagination.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function createPageProps<T>(
1616
const pageSize = pagination.pageSize ?? DEFAULT_PAGE_SIZE;
1717
const pagesCount = Math.ceil(items.length / pageSize);
1818
let pageIndex = currentPageIndex ?? 1;
19-
if (pageIndex < 1 || Number.isNaN(pageIndex)) {
19+
if (pageIndex < 1 || (pageIndex > pagesCount && !pagination.allowPageOutOfRange) || Number.isNaN(pageIndex)) {
2020
pageIndex = 1;
2121
}
2222
return { pageSize, pagesCount, pageIndex };

0 commit comments

Comments
 (0)