Material-ui: Pagination is ignoring siblingCount when boundaryCount is zero

Created on 13 Jun 2020  路  5Comments  路  Source: mui-org/material-ui

  • [x] The issue is present in the latest release.
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 馃槸

When boundaryCount is set to zero, Pagination:

  • shows only first and last pages, no matter what i set on siblingCount;
  • doesn麓t show the current page (if the current is not the first nor the last);
  • ignores siblingCount value not showing the always visible pages before and after the current page.

Expected Behavior 馃

Pagination should not ignore the siblingCount value when boundaryCount is set to zero.

Steps to Reproduce 馃暪

https://codesandbox.io/s/quirky-chebyshev-h25pc

Steps:

  1. Step thru pages and you'll realize Pagination is not showing the siblingCount always visible pages before and after the current page.
  2. Thats it.

Context 馃敠

I would like to have a Pagination with the previous, current e next page numbers.

Your Environment 馃寧

On chrome and firefox. I think the problem is not about the environment in this case.

| Tech | Version |
| ----------- | ------- |
| material-ui/core | v4.10.2 |
| React | 16.13.1 |
| Browser | Chrome 83.0.4103.61 |

bug 馃悰 Pagination good first issue

All 5 comments

@guimacrf Thanks for taking the time to report the issue What do you think of this patch? Do you want to work on it? :)

diff --git a/packages/material-ui-lab/src/Pagination/usePagination.js b/packages/material-ui-lab/src/Pagination/usePagination.js
index 300ee9574..9464af317 100644
--- a/packages/material-ui-lab/src/Pagination/usePagination.js
+++ b/packages/material-ui-lab/src/Pagination/usePagination.js
@@ -62,7 +62,7 @@ export default function usePagination(props = {}) {
       boundaryCount + siblingCount * 2 + 2,
     ),
     // Less than endPages
-    endPages[0] - 2,
+    endPages.length > 0 ? endPages[0] - 2 : Infinity,
   );

   // Basic list of items to render

@oliviertassinari, if @guimacrf doesn't want to take this I'm more than happy to.

@oliviertassinari , I want to work on it. Thanks for the opportunity.
I will reply about your sugestion tonight.

@guimacrf Thanks for taking the time to report the issue What do you think of this patch? Do you want to work on it? :)

diff --git a/packages/material-ui-lab/src/Pagination/usePagination.js b/packages/material-ui-lab/src/Pagination/usePagination.js
index 300ee9574..9464af317 100644
--- a/packages/material-ui-lab/src/Pagination/usePagination.js
+++ b/packages/material-ui-lab/src/Pagination/usePagination.js
@@ -62,7 +62,7 @@ export default function usePagination(props = {}) {
       boundaryCount + siblingCount * 2 + 2,
     ),
     // Less than endPages
-    endPages[0] - 2,
+    endPages.length > 0 ? endPages[0] - 2 : Infinity,
   );

   // Basic list of items to render

@oliviertassinari , I made the correction a little differently than you suggested, but following your idea. As you suggested, the last page appeared twice. Take a look:

diff --git a/packages/material-ui-lab/src/Pagination/usePagination.js b/packages/material-ui-lab/src/Pagination/usePagination.js
index 300ee9574..7391b7870 100644
--- a/packages/material-ui-lab/src/Pagination/usePagination.js
+++ b/packages/material-ui-lab/src/Pagination/usePagination.js
@@ -62,7 +62,7 @@ export default function usePagination(props = {}) {
       boundaryCount + siblingCount * 2 + 2,
     ),
     // Less than endPages
-    endPages[0] - 2,
+    endPages.length > 0 ? endPages[0] - 2 : count - 1,
   );

   // Basic list of items to render

Sending a pull request in a few minutes.

@guimacrf Thanks for looking into it, Infinity was probably not the best value 馃憤.

Was this page helpful?
0 / 5 - 0 ratings