Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions assets/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@
}
}

&-disabled {
cursor: not-allowed;
&:hover {
border-color: #d9d9d9;
a {
color: #d9d9d9;
}
}
}

&-active {
background-color: #2db7f5;
border-color: #2db7f5;
Expand Down
4 changes: 4 additions & 0 deletions src/Pager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const Pager = (props) => {
cls = `${cls} ${props.className}`;
}

if (!props.page) {
cls = `${cls} ${prefixCls}-disabled`;
}

const handleClick = () => {
props.onClick(props.page);
};
Expand Down
29 changes: 21 additions & 8 deletions src/Pagination.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<Pager
{...pagerProps}
key="noPager"
page={allPages}
className={`${prefixCls}-disabled`}
/>
);
}
for (let i = 1; i <= allPages; i++) {
const active = this.state.current === i;
pagerList.push(
<Pager
locale={locale}
rootPrefixCls={prefixCls}
onClick={this.handleChange}
onKeyPress={this.runIfEnter}
{...pagerProps}
key={i}
page={i}
active={active}
showTitle={props.showTitle}
itemRender={props.itemRender}
/>
);
}
Expand Down Expand Up @@ -578,8 +591,8 @@ export default class Pagination extends React.Component {
</li>
);
}
const prevDisabled = !this.hasPrev();
const nextDisabled = !this.hasNext();
const prevDisabled = !this.hasPrev() || !allPages;
const nextDisabled = !this.hasNext() || !allPages;
return (
<ul
className={`${prefixCls} ${props.className}`}
Expand Down
9 changes: 9 additions & 0 deletions tests/Pagination.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,15 @@ describe('current value on onShowSizeChange when total is 0', () => {
}, 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', () => {
Expand Down