Skip to content

Commit 0906a90

Browse files
feat: simple Pagination cant emit onChange when change page (#350)
* feat: simple Pagination cant emit onChange when change page * feat:revise pagination jumper.test when input blur * test:Pagination add call onChange when value changed and input blur * feat: simple Pagination test
1 parent ca84b62 commit 0906a90

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/Pagination.jsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,12 @@ class Pagination extends React.Component {
172172

173173
isValid = (page) => {
174174
const { total } = this.props;
175-
return isInteger(page) && page !== this.state.current && isInteger(total) && total > 0;
175+
return (
176+
isInteger(page) &&
177+
page !== this.state.current &&
178+
isInteger(total) &&
179+
total > 0
180+
);
176181
};
177182

178183
shouldDisplayQuickJumper = () => {
@@ -206,6 +211,11 @@ class Pagination extends React.Component {
206211
}
207212
};
208213

214+
handleBlur = (e) => {
215+
const value = this.getValidValue(e);
216+
this.handleChange(value);
217+
};
218+
209219
changePageSize = (size) => {
210220
let { current } = this.state;
211221
const newCurrent = calculatePage(size, this.state, this.props);
@@ -476,6 +486,7 @@ class Pagination extends React.Component {
476486
onKeyDown={this.handleKeyDown}
477487
onKeyUp={this.handleKeyUp}
478488
onChange={this.handleKeyUp}
489+
onBlur={this.handleBlur}
479490
size="3"
480491
/>
481492
<span className={`${prefixCls}-slash`}>/</span>

tests/simple.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ describe('simple Pagination', () => {
2222
wrapper.unmount();
2323
});
2424

25+
it('input change value will emit onChange when input blur', () => {
26+
const onChange = jest.fn();
27+
const component = mount(
28+
<Pagination simple total={25} onChange={onChange} />,
29+
);
30+
const greaterCurrent = component.find('.rc-pagination-simple');
31+
const input = greaterCurrent.find('input');
32+
input.simulate('change', { target: { value: '2' } });
33+
input.simulate('blur');
34+
expect(onChange).toBeCalled();
35+
});
36+
2537
it('default current page is 1', () => {
2638
expect(wrapper.state().current).toBe(1);
2739
});

0 commit comments

Comments
 (0)