diff --git a/src/Pagination.jsx b/src/Pagination.jsx index ff3f18c2..870c695b 100644 --- a/src/Pagination.jsx +++ b/src/Pagination.jsx @@ -172,7 +172,12 @@ class Pagination extends React.Component { isValid = (page) => { const { total } = this.props; - return isInteger(page) && page !== this.state.current && isInteger(total) && total > 0; + return ( + isInteger(page) && + page !== this.state.current && + isInteger(total) && + total > 0 + ); }; shouldDisplayQuickJumper = () => { @@ -206,6 +211,11 @@ class Pagination extends React.Component { } }; + handleBlur = (e) => { + const value = this.getValidValue(e); + this.handleChange(value); + }; + changePageSize = (size) => { let { current } = this.state; const newCurrent = calculatePage(size, this.state, this.props); @@ -476,6 +486,7 @@ class Pagination extends React.Component { onKeyDown={this.handleKeyDown} onKeyUp={this.handleKeyUp} onChange={this.handleKeyUp} + onBlur={this.handleBlur} size="3" /> / diff --git a/tests/simple.test.js b/tests/simple.test.js index db2fb34b..ca90c3a1 100644 --- a/tests/simple.test.js +++ b/tests/simple.test.js @@ -22,6 +22,18 @@ describe('simple Pagination', () => { wrapper.unmount(); }); + it('input change value will emit onChange when input blur', () => { + const onChange = jest.fn(); + const component = mount( + , + ); + const greaterCurrent = component.find('.rc-pagination-simple'); + const input = greaterCurrent.find('input'); + input.simulate('change', { target: { value: '2' } }); + input.simulate('blur'); + expect(onChange).toBeCalled(); + }); + it('default current page is 1', () => { expect(wrapper.state().current).toBe(1); });