Skip to content

Commit dd549f5

Browse files
authored
🆕 size changer will be shown when total >= 100 (#258)
1 parent ff396f5 commit dd549f5

File tree

6 files changed

+59
-8
lines changed

6 files changed

+59
-8
lines changed

HISTORY.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
# 2.1.0
2+
3+
- When `total` is greater then 100, will show size changer defaultly.
4+
- Update default page size options from `10,20,30,40` to `10,25,50,100`.
5+
16
# 2.0.0
27

3-
- Remove prop-types and react-lifecycles-compat
8+
- Remove `prop-types` and `react-lifecycles-compat`
49

510
# 1.20.0
611

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ React.render(<Pagination />, container);
6161
| defaultPageSize | default items per page | Number | 10 |
6262
| pageSize | items per page | Number | 10 |
6363
| onChange | page change callback | Function(current, pageSize) | - |
64-
| showSizeChanger | show pageSize changer | Bool | false |
64+
| showSizeChanger | show pageSize changer | Bool | `false` when total less then 100, `true` when otherwise |
6565
| pageSizeOptions | specify the sizeChanger selections | Array<String> | ['10', '20', '30', '40'] |
6666
| onShowSizeChange | pageSize change callback | Function(current, size) | - |
6767
| hideOnSinglePage | hide on single page | Bool | false |

examples/sizer.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ class App extends React.Component {
2828
/>
2929
<Pagination
3030
selectComponentClass={Select}
31-
showSizeChanger
31+
pageSize={this.state.pageSize}
32+
onShowSizeChange={this.onShowSizeChange}
33+
defaultCurrent={3}
34+
total={500}
35+
/>
36+
<Pagination
37+
selectComponentClass={Select}
38+
showSizeChanger={false}
3239
pageSize={this.state.pageSize}
3340
onShowSizeChange={this.onShowSizeChange}
3441
defaultCurrent={3}

src/Options.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import KEYCODE from './KeyCode';
44

55
class Options extends React.Component {
66
static defaultProps = {
7-
pageSizeOptions: ['10', '20', '30', '40'],
7+
pageSizeOptions: ['10', '25', '50', '100'],
88
};
99

1010
state = {

src/Pagination.jsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class Pagination extends React.Component {
3737
hideOnSinglePage: false,
3838
showPrevNextJumpers: true,
3939
showQuickJumper: false,
40-
showSizeChanger: false,
4140
showLessItems: false,
4241
showTitle: true,
4342
onShowSizeChange: noop,
@@ -278,6 +277,14 @@ class Pagination extends React.Component {
278277
hasNext = () =>
279278
this.state.current < calculatePage(undefined, this.state, this.props);
280279

280+
getShowSizeChanger() {
281+
const { showSizeChanger, total } = this.props;
282+
if (typeof showSizeChanger !== 'undefined') {
283+
return showSizeChanger;
284+
}
285+
return total >= 100;
286+
}
287+
281288
runIfEnter = (event, callback, ...restParams) => {
282289
if (event.key === 'Enter' || event.charCode === 13) {
283290
callback(...restParams);
@@ -337,7 +344,6 @@ class Pagination extends React.Component {
337344
showLessItems,
338345
showTitle,
339346
showTotal,
340-
showSizeChanger,
341347
simple,
342348
itemRender,
343349
showPrevNextJumpers,
@@ -669,7 +675,7 @@ class Pagination extends React.Component {
669675
rootPrefixCls={prefixCls}
670676
selectComponentClass={selectComponentClass}
671677
selectPrefixCls={selectPrefixCls}
672-
changeSize={showSizeChanger ? this.changePageSize : null}
678+
changeSize={this.getShowSizeChanger() ? this.changePageSize : null}
673679
current={current}
674680
pageSize={pageSize}
675681
pageSizeOptions={pageSizeOptions}

tests/index.test.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ describe('current value on onShowSizeChange when total is 0', () => {
323323
input.simulate('keyDown', { key: 'Enter', keyCode: 13, which: 13 });
324324
expect(onShowSizeChange).toHaveBeenLastCalledWith(
325325
wrapper.state().current,
326-
20,
326+
25,
327327
);
328328
});
329329

@@ -336,4 +336,37 @@ describe('current value on onShowSizeChange when total is 0', () => {
336336
const totalText = wrapper.find('.rc-pagination-total-text');
337337
expect(totalText.text()).toBe('0 - 0 of 0 items');
338338
});
339+
340+
it('size changer show logic', () => {
341+
const wrapper1 = mount(
342+
<Pagination
343+
selectComponentClass={Select}
344+
total={99}
345+
/>,
346+
);
347+
expect(wrapper1.exists('.rc-pagination-options-size-changer')).toBe(false);
348+
const wrapper2 = mount(
349+
<Pagination
350+
selectComponentClass={Select}
351+
total={100}
352+
/>,
353+
);
354+
expect(wrapper2.exists('.rc-pagination-options-size-changer')).toBe(true);
355+
const wrapper3 = mount(
356+
<Pagination
357+
selectComponentClass={Select}
358+
showSizeChanger={false}
359+
total={100}
360+
/>,
361+
);
362+
expect(wrapper3.exists('.rc-pagination-options-size-changer')).toBe(false);
363+
const wrapper4 = mount(
364+
<Pagination
365+
selectComponentClass={Select}
366+
showSizeChanger
367+
total={99}
368+
/>,
369+
);
370+
expect(wrapper4.exists('.rc-pagination-options-size-changer')).toBe(true);
371+
});
339372
});

0 commit comments

Comments
 (0)