Skip to content

Commit 27db430

Browse files
jennurkpsherva
authored andcommitted
pagination: add maxTotalResults to limit number of pages
1 parent 7c6d8a7 commit 27db430

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/lib/components/Pagination/Pagination.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ const Element = ({
9191
totalResults,
9292
onPageChange,
9393
options,
94+
maxTotalResults,
9495
...props
9596
}) => {
96-
const pages = Math.ceil(totalResults / currentSize);
9797
const boundaryRangeCount = options.boundaryRangeCount;
9898
const siblingRangeCount = options.siblingRangeCount;
9999
const showEllipsis = options.showEllipsis;
@@ -103,6 +103,10 @@ const Element = ({
103103
const showNext = options.showNext;
104104
const size = options.size;
105105

106+
const maxTotalPages = Math.floor(maxTotalResults / currentSize);
107+
const pages = Math.ceil(totalResults / currentSize);
108+
const totalDisplayedPages = Math.min(pages, maxTotalPages);
109+
106110
const { buildUID } = useContext(AppContext);
107111
if (currentPage > pages) onPageChange(pages);
108112

@@ -117,7 +121,7 @@ const Element = ({
117121
>
118122
<Paginator
119123
activePage={currentPage}
120-
totalPages={pages}
124+
totalPages={totalDisplayedPages}
121125
onPageChange={(_, { activePage }) => onPageChange(activePage)}
122126
boundaryRange={boundaryRangeCount}
123127
siblingRange={siblingRangeCount}
@@ -140,11 +144,13 @@ Element.propTypes = {
140144
onPageChange: PropTypes.func.isRequired,
141145
options: PropTypes.object,
142146
overridableId: PropTypes.string,
147+
maxTotalResults: PropTypes.number,
143148
};
144149

145150
Element.defaultProps = {
146151
options: {},
147152
overridableId: "",
153+
maxTotalResults: 10000,
148154
};
149155

150156
export default Overridable.component("Pagination", Pagination);

0 commit comments

Comments
 (0)