Skip to content

Commit de5b472

Browse files
authored
Merge 61a4549 into c4fcce6
2 parents c4fcce6 + 61a4549 commit de5b472

File tree

12 files changed

+88
-73
lines changed

12 files changed

+88
-73
lines changed

docs/demo/basic.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## simple
2+
3+
<code src="../examples/simple.jsx">

docs/demo/controlled.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## default
2+
3+
<code src="../examples/controlled.jsx">

docs/demo/default.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

docs/demo/simple.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
## simple
1+
## stupid
22

33
<code src="../examples/simple.jsx">

docs/demo/stupid.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

docs/examples/basic.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import '../../assets/index.less';
2+
import React from 'react';
3+
import Pagination from 'rc-pagination';
4+
5+
const App = () => (
6+
<>
7+
<Pagination total={25} />
8+
<Pagination total={50} />
9+
<Pagination total={60} />
10+
<Pagination total={70} />
11+
<Pagination total={80} />
12+
<Pagination total={90} />
13+
<Pagination total={100} />
14+
<Pagination total={120} />
15+
<Pagination total={500} />
16+
</>
17+
);
18+
19+
export default App;

docs/examples/controlled.jsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React, { useState } from 'react';
2+
import Pagination from 'rc-pagination';
3+
import '../../assets/index.less';
4+
import 'rc-select/assets/index.less';
5+
6+
const App = () => {
7+
const [current, setCurrent] = useState(1);
8+
const onChange = page => {
9+
setCurrent(page);
10+
};
11+
return (
12+
<Pagination
13+
onChange={onChange}
14+
current={current}
15+
total={25}
16+
/>
17+
);
18+
};
19+
20+
export default App;

docs/examples/default.jsx

Lines changed: 0 additions & 28 deletions
This file was deleted.

docs/examples/simple.jsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
1-
import '../../assets/index.less';
21
import React from 'react';
32
import Pagination from 'rc-pagination';
3+
import '../../assets/index.less';
44

5-
const App = () => (
6-
<>
7-
<Pagination total={25} />
8-
<Pagination total={50} />
9-
<Pagination total={60} />
10-
<Pagination total={70} />
11-
<Pagination total={80} />
12-
<Pagination total={90} />
13-
<Pagination total={100} />
14-
<Pagination total={120} />
15-
<Pagination total={500} />
16-
</>
17-
);
18-
19-
export default App;
5+
export default () => <Pagination simple defaultCurrent={1} total={50} />;

docs/examples/stupid.jsx

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/Pagination.jsx

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -253,32 +253,31 @@ class Pagination extends React.Component {
253253
}
254254
};
255255

256-
handleChange = (p) => {
257-
const { disabled } = this.props;
258-
259-
let page = p;
256+
handleChange = (page) => {
257+
const { disabled, onChange } = this.props;
258+
const { pageSize, current, currentInputValue } = this.state;
260259
if (this.isValid(page) && !disabled) {
261260
const currentPage = calculatePage(undefined, this.state, this.props);
261+
let newPage = page;
262262
if (page > currentPage) {
263-
page = currentPage;
263+
newPage = currentPage;
264264
} else if (page < 1) {
265-
page = 1;
265+
newPage = 1;
266266
}
267-
268267
if (!('current' in this.props)) {
269268
this.setState({
270-
current: page,
271-
currentInputValue: page,
269+
current: newPage,
272270
});
273271
}
274-
275-
const { pageSize } = this.state;
276-
this.props.onChange(page, pageSize);
277-
278-
return page;
272+
if (newPage !== currentInputValue) {
273+
this.setState({
274+
currentInputValue: newPage,
275+
});
276+
}
277+
onChange(newPage, pageSize);
278+
return newPage;
279279
}
280-
281-
return this.state.current;
280+
return current;
282281
};
283282

284283
prev = () => {

tests/simple.test.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
import { mount } from 'enzyme';
33
import Pagination from '../src';
44

@@ -34,6 +34,30 @@ describe('simple Pagination', () => {
3434
expect(onChange).toBeCalled();
3535
});
3636

37+
it('should return to 1 when blur goto input in uncontrol mode', () => {
38+
const component = mount(
39+
<Pagination simple defaultCurrent={1} total={25} />,
40+
);
41+
const input = component.find('.rc-pagination-simple').find('input');
42+
input.simulate('focus');
43+
input.simulate('change', { target: { value: '' } });
44+
input.simulate('blur');
45+
expect(input.getDOMNode().value).toBe('1');
46+
});
47+
48+
it('should return to 1 when blur goto input in control mode', () => {
49+
const App = () => {
50+
const [current, setCurrent] = useState(1);
51+
return <Pagination simple current={1} total={25} onChange={setCurrent} />;
52+
};
53+
const component = mount(<App />);
54+
const input = component.find('.rc-pagination-simple').find('input');
55+
input.simulate('focus');
56+
input.simulate('change', { target: { value: '' } });
57+
input.simulate('blur');
58+
expect(input.getDOMNode().value).toBe('1');
59+
});
60+
3761
it('default current page is 1', () => {
3862
expect(wrapper.state().current).toBe(1);
3963
});

0 commit comments

Comments
 (0)