Skip to content

Commit cd86b36

Browse files
committed
fix inputValue locked
fix ant-design/ant-design#13889
1 parent 8ee85ef commit cd86b36

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

src/Pagination.jsx

+10-9
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,20 @@ class Pagination extends React.Component {
116116
}
117117
}
118118

119-
static getDerivedStateFromProps(props, state) {
120-
let newState = {};
119+
static getDerivedStateFromProps(props, prevState) {
120+
const newState = {};
121121

122122
if ('current' in props) {
123-
newState = {
124-
current: props.current,
125-
currentInputValue: props.current,
126-
};
123+
newState.current = props.current;
124+
125+
if (props.current !== prevState.current) {
126+
newState.currentInputValue = newState.current;
127+
}
127128
}
128129

129-
if ('pageSize' in props) {
130-
let current = state.current;
131-
const newCurrent = calculatePage(props.pageSize, state, props);
130+
if ('pageSize' in props && props.pageSize !== prevState.pageSize) {
131+
let current = prevState.current;
132+
const newCurrent = calculatePage(props.pageSize, prevState, props);
132133
current = current > newCurrent ? newCurrent : current;
133134

134135
if (!('current' in props)) {

tests/Pagination.spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,23 @@ describe('Controlled Pagination', () => {
197197
ReactDOM.unmountComponentAtNode(container);
198198
});
199199

200+
it('not replace currentInputValue if current not change', (done) => {
201+
pagination.state.current = 1;
202+
pagination.state.currentInputValue = 1;
203+
pagination.forceUpdate();
204+
expect(pagination.state.current).to.be(1);
205+
expect(pagination.state.currentInputValue).to.be(1);
206+
207+
setTimeout(() => {
208+
pagination.state.currentInputValue = 1;
209+
pagination.forceUpdate();
210+
expect(pagination.state.current).to.be(2);
211+
expect(pagination.state.currentInputValue).to.be(1);
212+
213+
done();
214+
}, 10);
215+
});
216+
200217
it('current should equal defaultCurrent', () => {
201218
expect(pagination.state.current).to.be(2);
202219
});

0 commit comments

Comments
 (0)