Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TablePagination] Out of range warning when "count={-1}" #19874

Merged
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 ', () => {
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
it('should handle when count is out of range', () => {
let page = 1;
const wrapper = mount(
<table>
<TableFooter>
<TableBody>
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
<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(
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
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