Skip to content

✨ Combination of Simple mode pagination along with page size changer #530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/examples/simple.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import Pagination from 'rc-pagination';
import Select from 'rc-select';
import '../../assets/index.less';

export default () => (
Expand All @@ -12,5 +13,13 @@ export default () => (
total={50}
showTotal={(total) => `Total ${total} items`}
/>
<br />
<Pagination
simple
defaultCurrent={1}
total={50}
showSizeChanger
selectComponentClass={Select}
/>
</>
);
14 changes: 13 additions & 1 deletion src/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,19 @@ class Pagination extends React.Component<PaginationProps, PaginationState> {
>
{this.renderNext(nextPage)}
</li>
{gotoButton}
<Options
disabled={disabled}
locale={locale}
rootPrefixCls={prefixCls}
selectComponentClass={selectComponentClass}
selectPrefixCls={selectPrefixCls}
changeSize={this.getShowSizeChanger() ? this.changePageSize : null}
current={current}
pageSize={pageSize}
pageSizeOptions={pageSizeOptions}
quickGo={this.shouldDisplayQuickJumper() ? this.handleChange : null}
goButton={gotoButton}
/>
</ul>
);
}
Expand Down
3 changes: 1 addition & 2 deletions tests/jumper.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { mount } from 'enzyme';
import Pagination from '../src';

Expand Down Expand Up @@ -99,7 +98,7 @@ describe('simple quick jumper', () => {
});

it('should quick jump to expect page', () => {
const quickJumper = wrapper.find('.rc-pagination-simple');
const quickJumper = wrapper.find('.rc-pagination-options-quick-jumper');
const input = quickJumper.find('input');
const goButton = quickJumper.find('.go-button');
input.simulate('change', { target: { value: '2' } });
Expand Down
36 changes: 36 additions & 0 deletions tests/simple.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from 'react';
import { mount } from 'enzyme';
import Select from 'rc-select';
import Pagination from '../src';

describe('simple Pagination', () => {
Expand Down Expand Up @@ -84,4 +85,39 @@ describe('simple Pagination', () => {
expect(input.getDOMNode().value).toBe('3');
expect(component.state().current).toBe(3);
});

it('should merge custom pageSize to pageSizeOptions', () => {
const wrapper = mount(
<Pagination
simple
total={500}
pageSize={15}
showSizeChanger
selectComponentClass={Select}
/>,
);
wrapper.find(Select).find('input').simulate('mousedown');
expect(wrapper.find(Select).find('.rc-select-item').length).toBe(5);
});

it('should onChange called when pageSize change', () => {
const onChange = jest.fn();
const wrapper = mount(
<Pagination
simple
selectComponentClass={Select}
onChange={onChange}
total={500}
defaultPageSize={20}
/>,
);
wrapper.find(Select).find('input').simulate('mousedown');
expect(wrapper.find(Select).find('.rc-select-item').at(2).text()).toBe(
'50 条/页',
);
const pageSize1 = wrapper.find(Select).find('.rc-select-item').at(0);
pageSize1.simulate('click');
expect(onChange).toBeCalled();
expect(onChange).toHaveBeenLastCalledWith(1, 10);
});
});