Skip to content

Commit

Permalink
fix(Pagination): fix and indicate when pagination is disabled
Browse files Browse the repository at this point in the history
fixes #1938
  • Loading branch information
mthuret authored and vvo committed Feb 6, 2017
1 parent 0971330 commit 5f20199
Show file tree
Hide file tree
Showing 4 changed files with 459 additions and 204 deletions.
1 change: 1 addition & 0 deletions packages/react-instantsearch/src/components/LinkList.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default class LinkList extends Component {
item.disabled && 'itemDisabled',
item.modifier
)}
disabled={item.disabled}
>
{item.disabled ?
<span {...cx('itemLink', 'itemLinkDisabled')}>
Expand Down
5 changes: 2 additions & 3 deletions packages/react-instantsearch/src/components/Pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ class Pagination extends Component {
listComponent: ListComponent,
...otherProps
} = this.props;

const totalPages = Math.min(nbPages, maxPages);
const lastPage = totalPages;

Expand Down Expand Up @@ -163,7 +162,7 @@ class Pagination extends Component {
items.push({
key: 'next',
modifier: 'itemNext',
disabled: currentRefinement === lastPage,
disabled: currentRefinement === lastPage || lastPage <= 1,
label: translate('next'),
value: currentRefinement + 1,
ariaLabel: translate('ariaNext'),
Expand All @@ -173,7 +172,7 @@ class Pagination extends Component {
items.push({
key: 'last',
modifier: 'itemLast',
disabled: currentRefinement === lastPage,
disabled: currentRefinement === lastPage || lastPage <= 1,
label: translate('last'),
value: lastPage,
ariaLabel: translate('ariaLast'),
Expand Down
16 changes: 16 additions & 0 deletions packages/react-instantsearch/src/components/Pagination.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,22 @@ describe('Pagination', () => {
expect(tree).toMatchSnapshot();
});

it('disabled all button if no results', () => {
const tree = renderer.create(
<Pagination
{...REQ_PROPS}
maxPages={Number.POSITIVE_INFINITY}
showLast
showFirst
showNext
showPrevious
nbPages={0}
currentRefinement={1}
/>
).toJSON();
expect(tree).toMatchSnapshot();
});

it('refines its value when clicking on a page link', () => {
const refine = jest.fn();
const wrapper = mount(
Expand Down
Loading

0 comments on commit 5f20199

Please sign in to comment.