diff --git a/CHANGELOG.md b/CHANGELOG.md index 2abcd4551cc..e8a5848d50a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ **Bug fixes** - Fixed bug in `EuiDataGrid` where a custom `className` was also being passed to the full screen button ([#5050](https://github.com/elastic/eui/pull/5050)) +- Fixed rerender state issues in `PaginationButton` inside `EuiPagination` ([#5048](https://github.com/elastic/eui/pull/5048)) ## [`37.3.0`](https://github.com/elastic/eui/tree/v37.3.0) diff --git a/src/components/basic_table/__snapshots__/in_memory_table.test.tsx.snap b/src/components/basic_table/__snapshots__/in_memory_table.test.tsx.snap index 4339c4f6ef5..640ce543e3b 100644 --- a/src/components/basic_table/__snapshots__/in_memory_table.test.tsx.snap +++ b/src/components/basic_table/__snapshots__/in_memory_table.test.tsx.snap @@ -520,9 +520,13 @@ exports[`EuiInMemoryTable behavior pagination 1`] = ` void; +type SafeClickHandler = (e: MouseEvent, pageIndex: number) => void; export interface EuiPaginationProps { /** @@ -57,7 +58,7 @@ export const EuiPagination: FunctionComponent = ({ 'aria-controls': ariaControls, ...rest }) => { - const safeClick = (e: MouseEvent, pageIndex: number) => { + const safeClick: SafeClickHandler = (e, pageIndex) => { e.preventDefault(); if (ariaControls) { @@ -70,30 +71,9 @@ export const EuiPagination: FunctionComponent = ({ onPageClick(pageIndex); }; - const PaginationButton = ({ - pageIndex, - inList = true, - }: { - pageIndex: number; - inList?: boolean; - }) => { - const button = ( - safeClick(e, pageIndex)} - pageIndex={pageIndex} - {...(hasControl && { 'aria-controls': ariaControls })} - hideOnMobile - /> - ); - if (inList) { - return
  • {button}
  • ; - } + const sharedButtonProps = { activePage, pageCount, ariaControls, safeClick }; - return button; - }; const classes = classNames('euiPagination', className); const hasControl = ariaControls !== undefined; const pages = []; @@ -110,7 +90,9 @@ export const EuiPagination: FunctionComponent = ({ ); for (let i = firstPageInRange, index = 0; i < lastPageInRange; i++, index++) { - pages.push(); + pages.push( + + ); } let prevPageButtonProps = {}; @@ -152,7 +134,9 @@ export const EuiPagination: FunctionComponent = ({ const firstPageButtons = []; if (firstPageInRange > 0) { - firstPageButtons.push(); + firstPageButtons.push( + + ); if (firstPageInRange > 1 && firstPageInRange !== 2) { firstPageButtons.push( @@ -171,7 +155,9 @@ export const EuiPagination: FunctionComponent = ({
    ); } else if (firstPageInRange === 2) { - firstPageButtons.push(); + firstPageButtons.push( + + ); } } @@ -180,7 +166,11 @@ export const EuiPagination: FunctionComponent = ({ if (lastPageInRange < pageCount) { if (lastPageInRange + 1 === pageCount - 1) { lastPageButtons.push( - + ); } else if (lastPageInRange < pageCount - 1) { lastPageButtons.push( @@ -201,7 +191,11 @@ export const EuiPagination: FunctionComponent = ({ } lastPageButtons.push( - + ); } @@ -243,10 +237,18 @@ export const EuiPagination: FunctionComponent = ({ if (compressed) { const firstPageButtonCompressed = ( - + ); const lastPageButtonCompressed = ( - + ); return ( @@ -288,3 +290,36 @@ export const EuiPagination: FunctionComponent = ({ ); }; + +const PaginationButtonWrapper = ({ + pageIndex, + inList = true, + activePage, + pageCount, + ariaControls, + safeClick, +}: { + pageIndex: number; + inList?: boolean; + activePage: number; + pageCount: number; + ariaControls?: string; + safeClick: SafeClickHandler; +}) => { + const button = ( + safeClick(e, pageIndex)} + pageIndex={pageIndex} + aria-controls={ariaControls} + hideOnMobile + /> + ); + + if (inList) { + return
  • {button}
  • ; + } + + return button; +};