From bfe153695a9df65aabdb37bbf85e3361e26a9886 Mon Sep 17 00:00:00 2001 From: zy410419243 Date: Sat, 22 Dec 2018 11:17:46 +0800 Subject: [PATCH] pref: show pager even total is 0 --- assets/index.less | 10 ++++++++++ src/Pager.jsx | 4 ++++ src/Pagination.jsx | 29 +++++++++++++++++++++-------- tests/Pagination.spec.js | 9 +++++++++ 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/assets/index.less b/assets/index.less index 1cb82a02..f9d457f7 100644 --- a/assets/index.less +++ b/assets/index.less @@ -53,6 +53,16 @@ } } + &-disabled { + cursor: not-allowed; + &:hover { + border-color: #d9d9d9; + a { + color: #d9d9d9; + } + } + } + &-active { background-color: #2db7f5; border-color: #2db7f5; diff --git a/src/Pager.jsx b/src/Pager.jsx index fa578e82..421f9c9e 100644 --- a/src/Pager.jsx +++ b/src/Pager.jsx @@ -13,6 +13,10 @@ const Pager = (props) => { cls = `${cls} ${props.className}`; } + if (!props.page) { + cls = `${cls} ${prefixCls}-disabled`; + } + const handleClick = () => { props.onClick(props.page); }; diff --git a/src/Pagination.jsx b/src/Pagination.jsx index 44d04488..4fbd6025 100644 --- a/src/Pagination.jsx +++ b/src/Pagination.jsx @@ -425,19 +425,32 @@ export default class Pagination extends React.Component { } if (allPages <= 5 + pageBufferSize * 2) { + const pagerProps = { + locale, + rootPrefixCls: prefixCls, + onClick: this.handleChange, + onKeyPress: this.runIfEnter, + showTitle: props.showTitle, + itemRender: props.itemRender, + }; + if (!allPages) { + pagerList.push( + + ); + } for (let i = 1; i <= allPages; i++) { const active = this.state.current === i; pagerList.push( ); } @@ -578,8 +591,8 @@ export default class Pagination extends React.Component { ); } - const prevDisabled = !this.hasPrev(); - const nextDisabled = !this.hasNext(); + const prevDisabled = !this.hasPrev() || !allPages; + const nextDisabled = !this.hasNext() || !allPages; return (
    { }, 10); }, 10); }); + + it('when total is 0, pager should show and disabled', () => { + const itemButton = TestUtils.findRenderedDOMComponentWithClass( + pagination, + 'rc-pagination-item' + ); + expect(TestUtils.isDOMComponent(itemButton)).to.be(true); + expect(itemButton.className).to.contain('rc-pagination-item-disabled'); + }); }); describe('data and aria props', () => {