Skip to content

Commit

Permalink
feat(experimental-pagination): add onchange handler (#9355)
Browse files Browse the repository at this point in the history
Co-authored-by: Josefina Mancilla <[email protected]>
  • Loading branch information
tay1orjones and jnm2377 authored Aug 3, 2021
1 parent df847d0 commit 06acc24
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7644,6 +7644,9 @@ Map {
"itemsPerPageText": Object {
"type": "string",
},
"onChange": Object {
"type": "func",
},
"pageRangeText": Object {
"type": "func",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function Pagination({
itemsPerPageText,
itemRangeText,
itemText,
onChange,
pageRangeText,
pageSize,
pageSizes,
Expand All @@ -49,6 +50,18 @@ function Pagination({
setCurrentPage(Number(newPage));
}

function incrementPage() {
const page = currentPage + 1;
setCurrentPage(page);
onChange({ page, pageSize: currentPageSize });
}

function decrementPage() {
const page = currentPage - 1;
setCurrentPage(page);
onChange({ page, pageSize: currentPageSize });
}

const namespace = `${prefix}--unstable-pagination`;

return (
Expand Down Expand Up @@ -137,7 +150,7 @@ function Pagination({
[`${namespace}__button--no-index`]: backButtonDisabled,
}
)}
onClick={() => setCurrentPage(currentPage - 1)}
onClick={() => decrementPage()}
disabled={backButtonDisabled}
hasIconOnly
renderIcon={CaretLeft16}
Expand All @@ -153,7 +166,7 @@ function Pagination({
[`${namespace}__button--no-index`]: forwardButtonDisabled,
}
)}
onClick={() => setCurrentPage(currentPage + 1)}
onClick={() => incrementPage()}
disabled={forwardButtonDisabled}
hasIconOnly
renderIcon={CaretRight16}
Expand Down Expand Up @@ -216,6 +229,11 @@ Pagination.propTypes = {
*/
itemsPerPageText: PropTypes.string,

/**
* The callback function called when the current page changes.
*/
onChange: PropTypes.func,

/**
* The function returning a translatable text showing where the current page is,
* in a manner of the total number of pages.
Expand Down

0 comments on commit 06acc24

Please sign in to comment.