Skip to content

Commit 8571cb8

Browse files
author
愚指导
authored
fix: remove useless html when gotoButton is false (#120)
fix: remove useless html when gotoButton is false
1 parent eb0845d commit 8571cb8

File tree

2 files changed

+53
-15
lines changed

2 files changed

+53
-15
lines changed

src/Pagination.jsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,14 @@ export default class Pagination extends React.Component {
314314
>{goButton}</span>
315315
);
316316
}
317+
gotoButton = (
318+
<li
319+
title={props.showTitle ? `${locale.jump_to}${this.state.current}/${allPages}` : null}
320+
className={`${prefixCls}-simple-pager`}
321+
>
322+
{gotoButton}
323+
</li>
324+
);
317325
}
318326
return (
319327
<ul className={`${prefixCls} ${prefixCls}-simple ${props.className}`} style={props.style}>
@@ -352,12 +360,7 @@ export default class Pagination extends React.Component {
352360
>
353361
{props.itemRender(nextPage, 'next', <a className={`${prefixCls}-item-link`} />)}
354362
</li>
355-
<li
356-
title={props.showTitle ? `${locale.jump_to}${this.state.current}/${allPages}` : null}
357-
className={`${prefixCls}-simple-pager`}
358-
>
359-
{gotoButton}
360-
</li>
363+
{gotoButton}
361364
</ul>
362365
);
363366
}

tests/Pagination.spec.js

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -421,21 +421,12 @@ describe('simple Pagination', () => {
421421
const container = document.createElement('div');
422422
document.body.appendChild(container);
423423

424-
let current = 1;
425-
let pageSize;
426-
function onChange(page, pSize) {
427-
current = page;
428-
pageSize = pSize;
429-
}
430-
431424
beforeEach((done) => {
432425
ReactDOM.render(
433426
<Pagination
434427
simple
435-
onChange={onChange}
436428
defaultCurrent={1}
437429
total={25}
438-
showQuickJumper={{ goButton: <button>go</button> }}
439430
showTotal={(total, range) => `${range[0]} - ${range[1]} of ${total} items`}
440431
/>,
441432
container,
@@ -465,6 +456,50 @@ describe('simple Pagination', () => {
465456
expect(prevButton.getAttribute('aria-disabled')).to.equal('true');
466457
});
467458

459+
it('no quick jump', () => {
460+
const simplePagers = TestUtils.scryRenderedDOMComponentsWithClass(
461+
pagination,
462+
'rc-pagination-simple-pager'
463+
);
464+
expect(simplePagers.length).to.be(1);
465+
});
466+
});
467+
468+
469+
describe('simple Pagination with quick jump', () => {
470+
let pagination = null;
471+
const container = document.createElement('div');
472+
document.body.appendChild(container);
473+
474+
let current = 1;
475+
let pageSize;
476+
function onChange(page, pSize) {
477+
current = page;
478+
pageSize = pSize;
479+
}
480+
481+
beforeEach((done) => {
482+
ReactDOM.render(
483+
<Pagination
484+
simple
485+
onChange={onChange}
486+
defaultCurrent={1}
487+
total={25}
488+
showQuickJumper={{ goButton: <button>go</button> }}
489+
showTotal={(total, range) => `${range[0]} - ${range[1]} of ${total} items`}
490+
/>,
491+
container,
492+
function () {
493+
pagination = this;
494+
done();
495+
},
496+
);
497+
});
498+
499+
afterEach(() => {
500+
ReactDOM.unmountComponentAtNode(container);
501+
});
502+
468503
it('should quick jump to expect page', (done) => {
469504
const quickJumper = TestUtils.findRenderedDOMComponentWithClass(
470505
pagination,

0 commit comments

Comments
 (0)