Skip to content

Commit 8f7c71b

Browse files
authored
fix: page count should be 1 when total is 0 (#344)
close ant-design/ant-design#31684
1 parent 95307cb commit 8f7c71b

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/Pager.jsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@
22
import React from 'react';
33
import classNames from 'classnames';
44

5-
const Pager = props => {
5+
const Pager = (props) => {
66
const prefixCls = `${props.rootPrefixCls}-item`;
7-
const cls = classNames(prefixCls, `${prefixCls}-${props.page}`, {
8-
[`${prefixCls}-active`]: props.active,
9-
[props.className]: !!props.className,
10-
[`${prefixCls}-disabled`]: !props.page,
11-
});
7+
const cls = classNames(
8+
prefixCls,
9+
`${prefixCls}-${props.page}`,
10+
{
11+
[`${prefixCls}-active`]: props.active,
12+
[props.className]: !!props.className,
13+
[`${prefixCls}-disabled`]: !props.page,
14+
},
15+
props.className,
16+
);
1217

1318
const handleClick = () => {
1419
props.onClick(props.page);
1520
};
1621

17-
const handleKeyPress = e => {
22+
const handleKeyPress = (e) => {
1823
props.onKeyPress(e, props.onClick, props.page);
1924
};
2025

src/Pagination.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,8 @@ class Pagination extends React.Component {
509509
<Pager
510510
{...pagerProps}
511511
key="noPager"
512-
page={allPages}
513-
className={`${prefixCls}-disabled`}
512+
page={1}
513+
className={`${prefixCls}-item-disabled`}
514514
/>,
515515
);
516516
}

tests/index.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,10 @@ describe('current value on onShowSizeChange when total is 0', () => {
324324
);
325325
});
326326

327-
it('when total is 0, pager should show and disabled', () => {
327+
it('when total is 0, pager should show `1` and being disabled', () => {
328328
const itemButton = wrapper.find('.rc-pagination-item');
329329
expect(itemButton.hasClass('rc-pagination-item-disabled')).toBe(true);
330+
expect(itemButton.text()).toBe('1');
330331
});
331332

332333
it('when total is 0, `from` and `to` should be 0', () => {

0 commit comments

Comments
 (0)