Skip to content

Commit

Permalink
Prevent breaks to be displayed when both pageRangeDisplayed and `ma…
Browse files Browse the repository at this point in the history
…rginPagesDisplayed` are 0
  • Loading branch information
MonsieurV committed Dec 2, 2021
1 parent 755e157 commit d6caa47
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

- Removed support for depecrated `extraAriaContext` (please use `ariaLabelBuilder` instead)

## >= 8.1.0

- Prevent breaks to be displayed when both `pageRangeDisplayed` and `marginPagesDisplayed` are 0

## >= 8.0.3

- Fix bug on `marginPagesDisplayed={0}` (see: https://github.com/AdeleD/react-paginate/pull/396)
Expand Down
41 changes: 41 additions & 0 deletions __tests__/PaginationBoxView-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2183,4 +2183,45 @@ describe('Test custom props', () => {
).toBe('7');
});
});

describe('Prevent breaks when only one active page', () => {
it('does not show break', () => {
const pagination = ReactTestUtils.renderIntoDocument(
<PaginationBoxView
pageRangeDisplayed={0}
pageCount={12}
marginPagesDisplayed={0}
/>
);

const elmts = ReactTestUtils.scryRenderedDOMComponentsWithTag(
pagination,
'a'
);
const next = elmts[elmts.length - 1];

expect(
ReactDOM.findDOMNode(pagination).querySelectorAll('.break a').length
).toBe(0);
expect(
ReactDOM.findDOMNode(pagination).querySelectorAll('.selected a').length
).toBe(1);
expect(
ReactDOM.findDOMNode(pagination).querySelector('.selected a')
.textContent
).toBe('1');

ReactTestUtils.Simulate.click(next);
expect(
ReactDOM.findDOMNode(pagination).querySelectorAll('.break a').length
).toBe(0);
expect(
ReactDOM.findDOMNode(pagination).querySelectorAll('.selected a').length
).toBe(1);
expect(
ReactDOM.findDOMNode(pagination).querySelector('.selected a')
.textContent
).toBe('2');
});
});
});
2 changes: 1 addition & 1 deletion demo/js/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ export class App extends Component {
breakClassName="page-item"
breakLinkClassName="page-link"
pageCount={20}
pageRangeDisplayed={4}
marginPagesDisplayed={2}
pageRangeDisplayed={5}
onPageChange={this.handlePageClick}
containerClassName="pagination justify-content-center"
pageClassName="page-item"
Expand Down
2 changes: 1 addition & 1 deletion dist/react-paginate.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/react-paginate.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-paginate",
"version": "8.0.3",
"version": "8.1.0",
"description": "A ReactJS component that creates a pagination.",
"main": "./dist/react-paginate.js",
"repository": {
Expand Down
4 changes: 3 additions & 1 deletion react_components/PaginationBoxView.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,9 @@ export default class PaginationBoxView extends Component {
if (
breakLabel &&
pagesBreaking.length > 0 &&
pagesBreaking[pagesBreaking.length - 1].display !== breakView
pagesBreaking[pagesBreaking.length - 1].display !== breakView &&
// We do not show break if only one active page is displayed.
(pageRangeDisplayed > 0 || marginPagesDisplayed > 0)
) {
breakView = (
<BreakView
Expand Down

0 comments on commit d6caa47

Please sign in to comment.