Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions packages/material-ui/src/TablePagination/TablePagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ TablePagination.propTypes = {
*/
page: chainPropTypes(PropTypes.number.isRequired, props => {
const { count, page, rowsPerPage } = props;

if (count === -1) {
return null;
}

const newLastPage = Math.max(0, Math.ceil(count / rowsPerPage) - 1);
if (page < 0 || page > newLastPage) {
return new Error(
Expand Down
28 changes: 14 additions & 14 deletions packages/material-ui/src/TablePagination/TablePagination.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import TableFooter from '../TableFooter';
import TableCell from '../TableCell';
import Typography from '../Typography';
import TableRow from '../TableRow';
import TableBody from '../TableBody';
import TablePagination from './TablePagination';

describe('<TablePagination />', () => {
Expand Down Expand Up @@ -200,29 +201,28 @@ describe('<TablePagination />', () => {
assert.strictEqual(page, 0);
});

it('should display 0 as start number if the table is empty ', () => {
it('should handle when count is out of range', () => {
let page = 1;
const wrapper = mount(
<table>
<TableFooter>
<TableBody>
<TableRow>
<TablePagination
count={0}
page={0}
count={-1}
page={page}
onChangePage={(event, nextPage) => {
page = nextPage;
}}
rowsPerPage={10}
onChangePage={noop}
onChangeRowsPerPage={noop}
/>
</TableRow>
</TableFooter>
</TableBody>
</table>,
);
assert.strictEqual(
wrapper
.find(Typography)
.at(1)
.text(),
'0-0 of 0',
);

const nextButton = wrapper.find(IconButton).at(1);
nextButton.simulate('click');
assert.strictEqual(page, 2);
});

it('should hide the rows per page selector if there are less than two options', () => {
Expand Down