Skip to content

Commit

Permalink
[TablePagination] Re-introduce deprecated onChangePage to `ActionsC…
Browse files Browse the repository at this point in the history
…omponent` (#27407)

Co-authored-by: Marija Najdova <[email protected]>
  • Loading branch information
eps1lon and mnajdova authored Jul 27, 2021
1 parent fcd8647 commit bb3b9ad
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
8 changes: 4 additions & 4 deletions packages/material-ui/src/TablePagination/TablePagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ const TablePagination = React.forwardRef(function TablePagination(props, ref) {
labelRowsPerPage = 'Rows per page:',
nextIconButtonProps,
nextIconButtonText = 'Next page',
onChangePage: onChangePageProp,
onPageChange: onPageChangeProp,
onChangePage,
onPageChange,
onChangeRowsPerPage: onChangeRowsPerPageProp,
onRowsPerPageChange: onRowsPerPageChangeProp,
page,
Expand All @@ -100,7 +100,6 @@ const TablePagination = React.forwardRef(function TablePagination(props, ref) {
...other
} = props;

const onChangePage = onChangePageProp || onPageChangeProp;
const onChangeRowsPerPage = onChangeRowsPerPageProp || onRowsPerPageChangeProp;

let colSpan;
Expand Down Expand Up @@ -167,7 +166,8 @@ const TablePagination = React.forwardRef(function TablePagination(props, ref) {
'aria-label': nextIconButtonText,
...nextIconButtonProps,
}}
onPageChange={onChangePage}
onChangePage={onChangePage}
onPageChange={onPageChange}
page={page}
rowsPerPage={rowsPerPage}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export interface TablePaginationActionsProps extends React.HTMLAttributes<HTMLDi
backIconButtonProps?: Partial<IconButtonProps>;
count: number;
nextIconButtonProps?: Partial<IconButtonProps>;
/**
* @deprecated Use onPageChange instead.
*/
onChangePage: (event: React.MouseEvent<HTMLButtonElement> | null, page: number) => void;
onPageChange: (event: React.MouseEvent<HTMLButtonElement> | null, page: number) => void;
page: number;
rowsPerPage: number;
Expand Down
14 changes: 12 additions & 2 deletions packages/material-ui/src/TablePagination/TablePaginationActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const TablePaginationActions = React.forwardRef(function TablePaginationActions(
backIconButtonProps,
count,
nextIconButtonProps,
onPageChange,
onChangePage = () => {},
onPageChange = () => {},
page,
rowsPerPage,
...other
Expand All @@ -22,10 +23,12 @@ const TablePaginationActions = React.forwardRef(function TablePaginationActions(
const theme = useTheme();

const handleBackButtonClick = (event) => {
onChangePage(event, page - 1);
onPageChange(event, page - 1);
};

const handleNextButtonClick = (event) => {
onChangePage(event, page + 1);
onPageChange(event, page + 1);
};

Expand Down Expand Up @@ -70,7 +73,14 @@ TablePaginationActions.propTypes = {
* @param {object} event The event source of the callback.
* @param {number} page The page selected.
*/
onPageChange: PropTypes.func.isRequired,
onChangePage: PropTypes.func,
/**
* Callback fired when the page is changed.
*
* @param {object} event The event source of the callback.
* @param {number} page The page selected.
*/
onPageChange: PropTypes.func,
/**
* The zero-based index of the current page.
*/
Expand Down

0 comments on commit bb3b9ad

Please sign in to comment.