Skip to content

Commit ca84b62

Browse files
authored
fix(Pagination): onChange should be forbidden when total is zero (#347)
* fix(Pagination): handle_change is forbidden when total is falsy or zero * fix(Pagination): add test case
1 parent 24d24d6 commit ca84b62

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Pagination.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ class Pagination extends React.Component {
170170
this.paginationNode = node;
171171
};
172172

173-
isValid = (page) => isInteger(page) && page !== this.state.current;
173+
isValid = (page) => {
174+
const { total } = this.props;
175+
return isInteger(page) && page !== this.state.current && isInteger(total) && total > 0;
176+
};
174177

175178
shouldDisplayQuickJumper = () => {
176179
const { showQuickJumper, pageSize, total } = this.props;

tests/index.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,27 @@ import { mount } from 'enzyme';
33
import Select from 'rc-select';
44
import Pagination from '../src';
55

6+
describe('Default Pagination', () => {
7+
let wrapper;
8+
const onChange = jest.fn();
9+
10+
beforeEach(() => {
11+
wrapper = mount(<Pagination onChange={onChange} />);
12+
});
13+
14+
afterEach(() => {
15+
wrapper.unmount();
16+
onChange.mockReset();
17+
});
18+
19+
it('onChange should be forbidden when total is default', () => {
20+
const pagers = wrapper.find('.rc-pagination-item');
21+
const page1 = pagers.at(0);
22+
page1.simulate('click');
23+
expect(onChange).toBeCalledTimes(0);
24+
});
25+
});
26+
627
describe('Uncontrolled Pagination', () => {
728
let wrapper;
829
const onChange = jest.fn();

0 commit comments

Comments
 (0)