From 12a855c0009711e7ad44d1724e1e75b4d751f9e9 Mon Sep 17 00:00:00 2001 From: Krisztina Kovari Date: Tue, 1 Oct 2024 14:00:20 +0200 Subject: [PATCH] also handle boundaries on mobile --- .../react-pagination/hooks/usePagination.test.ts | 2 +- packages/react-pagination/hooks/usePagination.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/react-pagination/hooks/usePagination.test.ts b/packages/react-pagination/hooks/usePagination.test.ts index a30ee619..1654595b 100644 --- a/packages/react-pagination/hooks/usePagination.test.ts +++ b/packages/react-pagination/hooks/usePagination.test.ts @@ -67,7 +67,7 @@ describe("usePagination ", () => { pages: 20, initialPage: 1, siblings: 1, - boundaries: 1, + boundaries: 2, isMobile: true, }), ); diff --git a/packages/react-pagination/hooks/usePagination.ts b/packages/react-pagination/hooks/usePagination.ts index 28d02d7b..a1cedd5c 100644 --- a/packages/react-pagination/hooks/usePagination.ts +++ b/packages/react-pagination/hooks/usePagination.ts @@ -105,13 +105,17 @@ export function usePagination( 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, + ) : [], ]; @@ -119,12 +123,12 @@ export function usePagination( segments, computedPages, responsiveSiblings, - boundaries, + responsiveBoundaries, gapSize, ); }, [ page, - boundaries, + responsiveBoundaries, responsiveSiblings, clampedSequence, computedPages, @@ -145,6 +149,8 @@ export function usePagination( const next = () => setPage(page + 1); const previous = () => setPage(page - 1); + console.log("RANGE", range); + return { page, setPage,