Skip to content

Commit

Permalink
also handle boundaries on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
krystonen committed Oct 1, 2024
1 parent ffb2888 commit 12a855c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/react-pagination/hooks/usePagination.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe("usePagination ", () => {
pages: 20,
initialPage: 1,
siblings: 1,
boundaries: 1,
boundaries: 2,
isMobile: true,
}),
);
Expand Down
14 changes: 10 additions & 4 deletions packages/react-pagination/hooks/usePagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,30 @@ export function usePagination<T>(
const { boundaries = 1, siblings = 1, gapSize = 1 } = props;

const responsiveSiblings = props.isMobile ? 0 : siblings;
const responsiveBoundaries = props.isMobile ? 1 : boundaries;

const range = useMemo(() => {
const segments: [number[], number[], number[]] = [
boundaries ? clampedSequence(1, boundaries) : [],
clampedSequence(page - responsiveSiblings, page + responsiveSiblings),
boundaries
? clampedSequence(computedPages + 1 - boundaries, computedPages)
responsiveBoundaries
? clampedSequence(
computedPages + 1 - responsiveBoundaries,
computedPages,
)
: [],
];

return formatSegments(
segments,
computedPages,
responsiveSiblings,
boundaries,
responsiveBoundaries,
gapSize,
);
}, [

Check warning on line 129 in packages/react-pagination/hooks/usePagination.ts

View workflow job for this annotation

GitHub Actions / check / Check Quality

React Hook useMemo has a missing dependency: 'boundaries'. Either include it or remove the dependency array
page,
boundaries,
responsiveBoundaries,
responsiveSiblings,
clampedSequence,
computedPages,
Expand All @@ -145,6 +149,8 @@ export function usePagination<T>(
const next = () => setPage(page + 1);
const previous = () => setPage(page - 1);

console.log("RANGE", range);

return {
page,
setPage,
Expand Down

0 comments on commit 12a855c

Please sign in to comment.