Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination: negative page item/page numbers on empty content #31

Closed
5 tasks done
ZEISSLaurinAgostini opened this issue Feb 12, 2019 · 1 comment
Closed
5 tasks done
Labels
bug Something isn't working

Comments

@ZEISSLaurinAgostini
Copy link
Contributor

ZEISSLaurinAgostini commented Feb 12, 2019

Bug Report

Prerequisites

  • Can you reproduce the problem in a MWE?
  • Are you running the latest version?
  • Did you check the FAQs to see if that helps you?
  • Are you reporting to the correct repository?
  • Did you perform a search in the issues?

For more information, see the CONTRIBUTING guide.

Versions

0.5.0

Description

When changing the items per page on empty content, the item range will jump to negative numbers and you can select negative page numbers.

Steps to Reproduce

  1. Create a Pagination component without content (e.g. empty array) and more than one items per page size available
const { Pagination } = require('precise-ui');
const data = Array();

<Pagination size={[20, 50, 100]}>
  {data}
</Pagination>
  1. Change the items per page

Expected behavior: Nothing should happen

Actual behavior: The items range will jump to a negative number (e.g. -49 - 0 of 0) and you can go to a previous (negative) page with the arrow button

Environment details: Windows 10, Google Chrome

Possible Solution

Line 131 in src/components/Pagination/index.tsx:
const maxPageCount = Math.ceil(total / size) - 1;
causes this issue, because for total == 0, the maxPageCount will be -1.

I already fixed and tested this and added more checks for this issue on other positions.

PR will come.

@FlorianRappl
Copy link
Collaborator

Cool thanks for contributing! <3

Would

const maxPageCount = Math.max(Math.ceil(total / size) - 1, 0);

solve this? I think this should be robust enough, or can you think of any other edge case?

@FlorianRappl FlorianRappl added the bug Something isn't working label Feb 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants