Skip to content

Commit 31b616c

Browse files
authored
fix: showTotal should work on simple mode (#433)
* Update Pagination.jsx simple 不覆盖会 showTotal 配置选项 * Update Pagination.jsx * Update Pagination.jsx * Update simple.jsx
1 parent 4d65a3d commit 31b616c

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

docs/examples/simple.jsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,15 @@ import React from 'react';
22
import Pagination from 'rc-pagination';
33
import '../../assets/index.less';
44

5-
export default () => <Pagination simple defaultCurrent={1} total={50} />;
5+
export default () => (
6+
<>
7+
<Pagination simple defaultCurrent={1} total={50} />
8+
<br />
9+
<Pagination
10+
simple
11+
defaultCurrent={1}
12+
total={50}
13+
showTotal={(total) => `Total ${total} items`}
14+
/>
15+
</>
16+
);

src/Pagination.jsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,15 @@ class Pagination extends React.Component {
425425
},
426426
{},
427427
);
428+
429+
const totalText = showTotal && (
430+
<li className={`${prefixCls}-total-text`}>
431+
{showTotal(total, [
432+
total === 0 ? 0 : (current - 1) * pageSize + 1,
433+
current * pageSize > total ? total : current * pageSize,
434+
])}
435+
</li>
436+
);
428437

429438
if (simple) {
430439
if (goButton) {
@@ -467,6 +476,7 @@ class Pagination extends React.Component {
467476
ref={this.savePaginationNode}
468477
{...dataOrAriaAttributeProps}
469478
>
479+
{totalText}
470480
<li
471481
title={showTitle ? locale.prev_page : null}
472482
onClick={this.prev}
@@ -661,19 +671,7 @@ class Pagination extends React.Component {
661671
pagerList.push(lastPager);
662672
}
663673
}
664-
665-
let totalText = null;
666-
667-
if (showTotal) {
668-
totalText = (
669-
<li className={`${prefixCls}-total-text`}>
670-
{showTotal(total, [
671-
total === 0 ? 0 : (current - 1) * pageSize + 1,
672-
current * pageSize > total ? total : current * pageSize,
673-
])}
674-
</li>
675-
);
676-
}
674+
677675
const prevDisabled = !this.hasPrev() || !allPages;
678676
const nextDisabled = !this.hasNext() || !allPages;
679677
return (

0 commit comments

Comments
 (0)