Skip to content

Commit a2bddd3

Browse files
author
愚指导
authored
fix custom showQuickJumper goButton not work bug react-component#117 (react-component#118)
* fix custom showQuickJumper goButton not work bug react-component#117
1 parent 9639beb commit a2bddd3

File tree

3 files changed

+154
-13
lines changed

3 files changed

+154
-13
lines changed

src/Options.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,12 @@ class Options extends React.Component {
112112
</button>
113113
);
114114
} else {
115-
gotoButton = goButton;
115+
gotoButton = (
116+
<span
117+
onClick={this.go}
118+
onKeyUp={this.go}
119+
>{goButton}</span>
120+
);
116121
}
117122
}
118123
goInput = (

src/Pagination.jsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -298,21 +298,21 @@ export default class Pagination extends React.Component {
298298
if (goButton) {
299299
if (typeof goButton === 'boolean') {
300300
gotoButton = (
301-
<li
302-
title={props.showTitle ? `${locale.jump_to}${this.state.current}/${allPages}` : null}
303-
className={`${prefixCls}-simple-pager`}
301+
<button
302+
type="button"
303+
onClick={this.handleGoTO}
304+
onKeyUp={this.handleGoTO}
304305
>
305-
<button
306-
type="button"
307-
onClick={this.handleGoTO}
308-
onKeyUp={this.handleGoTO}
309-
>
310306
{locale.jump_to_confirm}
311-
</button>
312-
</li>
307+
</button>
313308
);
314309
} else {
315-
gotoButton = goButton;
310+
gotoButton = (
311+
<span
312+
onClick={this.handleGoTO}
313+
onKeyUp={this.handleGoTO}
314+
>{goButton}</span>
315+
);
316316
}
317317
}
318318
return (
@@ -352,7 +352,12 @@ export default class Pagination extends React.Component {
352352
>
353353
{props.itemRender(nextPage, 'next', <a className={`${prefixCls}-item-link`} />)}
354354
</li>
355-
{gotoButton}
355+
<li
356+
title={props.showTitle ? `${locale.jump_to}${this.state.current}/${allPages}` : null}
357+
className={`${prefixCls}-simple-pager`}
358+
>
359+
{gotoButton}
360+
</li>
356361
</ul>
357362
);
358363
}

tests/Pagination.spec.js

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,134 @@ describe('hideOnSinglePage props', () => {
357357
);
358358
});
359359
});
360+
361+
describe('custom showQuickJumper button Pagination', () => {
362+
let pagination = null;
363+
const container = document.createElement('div');
364+
document.body.appendChild(container);
365+
366+
let current = 1;
367+
let pageSize;
368+
function onChange(page, pSize) {
369+
current = page;
370+
pageSize = pSize;
371+
}
372+
373+
beforeEach((done) => {
374+
ReactDOM.render(
375+
<Pagination
376+
onChange={onChange}
377+
defaultCurrent={1}
378+
total={25}
379+
showQuickJumper={{ goButton: <button>go</button> }}
380+
showTotal={(total, range) => `${range[0]} - ${range[1]} of ${total} items`}
381+
/>,
382+
container,
383+
function () {
384+
pagination = this;
385+
done();
386+
},
387+
);
388+
});
389+
390+
afterEach(() => {
391+
ReactDOM.unmountComponentAtNode(container);
392+
});
393+
394+
it('should quick jump to expect page', (done) => {
395+
const quickJumper = TestUtils.findRenderedDOMComponentWithClass(
396+
pagination,
397+
'rc-pagination-options-quick-jumper'
398+
);
399+
const input = quickJumper.querySelector('input');
400+
const goButton = quickJumper.querySelector('button');
401+
expect(TestUtils.isDOMComponent(quickJumper)).to.be(true);
402+
expect(TestUtils.isDOMComponent(input)).to.be(true);
403+
expect(TestUtils.isDOMComponent(goButton)).to.be(true);
404+
input.value = '2';
405+
Simulate.change(input);
406+
setTimeout(() => {
407+
Simulate.click(goButton);
408+
setTimeout(() => {
409+
expect(pagination.state.current).to.be(2);
410+
expect(current).to.be(2);
411+
expect(pageSize).to.be(10);
412+
done();
413+
}, 10);
414+
}, 10);
415+
});
416+
});
417+
418+
419+
describe('simple Pagination', () => {
420+
let pagination = null;
421+
const container = document.createElement('div');
422+
document.body.appendChild(container);
423+
424+
let current = 1;
425+
let pageSize;
426+
function onChange(page, pSize) {
427+
current = page;
428+
pageSize = pSize;
429+
}
430+
431+
beforeEach((done) => {
432+
ReactDOM.render(
433+
<Pagination
434+
simple
435+
onChange={onChange}
436+
defaultCurrent={1}
437+
total={25}
438+
showQuickJumper={{ goButton: <button>go</button> }}
439+
showTotal={(total, range) => `${range[0]} - ${range[1]} of ${total} items`}
440+
/>,
441+
container,
442+
function () {
443+
pagination = this;
444+
done();
445+
},
446+
);
447+
});
448+
449+
afterEach(() => {
450+
ReactDOM.unmountComponentAtNode(container);
451+
});
452+
453+
it('default current page is 1', () => {
454+
const current3 = pagination.state.current;
455+
expect(current3).to.be(1);
456+
});
457+
458+
it('prev-button should be disabled', () => {
459+
const prevButton = TestUtils.findRenderedDOMComponentWithClass(
460+
pagination,
461+
'rc-pagination-prev'
462+
);
463+
expect(TestUtils.isDOMComponent(prevButton)).to.be(true);
464+
expect(prevButton.className).to.contain('rc-pagination-disabled');
465+
expect(prevButton.getAttribute('aria-disabled')).to.equal('true');
466+
});
467+
468+
it('should quick jump to expect page', (done) => {
469+
const quickJumper = TestUtils.findRenderedDOMComponentWithClass(
470+
pagination,
471+
'rc-pagination-simple'
472+
);
473+
const input = quickJumper.querySelector('input');
474+
const goButton = quickJumper.querySelector('button');
475+
expect(TestUtils.isDOMComponent(quickJumper)).to.be(true);
476+
expect(TestUtils.isDOMComponent(input)).to.be(true);
477+
expect(TestUtils.isDOMComponent(goButton)).to.be(true);
478+
input.value = '2';
479+
Simulate.change(input);
480+
setTimeout(() => {
481+
Simulate.click(goButton);
482+
setTimeout(() => {
483+
expect(pagination.state.current).to.be(2);
484+
expect(current).to.be(2);
485+
expect(pageSize).to.be(10);
486+
done();
487+
}, 10);
488+
}, 10);
489+
});
490+
});

0 commit comments

Comments
 (0)