diff --git a/packages/react-core/src/components/Pagination/OptionsToggle.tsx b/packages/react-core/src/components/Pagination/OptionsToggle.tsx index 4d26714132f..a8372398bf6 100644 --- a/packages/react-core/src/components/Pagination/OptionsToggle.tsx +++ b/packages/react-core/src/components/Pagination/OptionsToggle.tsx @@ -44,7 +44,6 @@ export interface OptionsToggleProps extends React.HTMLProps { widgetId?: string; } -let toggleId = 0; export const OptionsToggle: React.FunctionComponent = ({ itemsTitle = 'items', optionsToggle, @@ -95,7 +94,7 @@ export const OptionsToggle: React.FunctionComponent = ({ onToggle={onToggle} isDisabled={isDisabled || (itemCount && itemCount <= 0)} isOpen={isOpen} - id={`${widgetId}-toggle-${toggleId++}`} + {...(widgetId && { id: `${widgetId}-toggle` })} className={isDiv ? styles.optionsMenuToggleButton : toggleClasses} parentRef={parentRef} aria-haspopup="listbox" diff --git a/packages/react-core/src/components/Pagination/Pagination.tsx b/packages/react-core/src/components/Pagination/Pagination.tsx index 6fd8fe5cc44..b54da5a613a 100644 --- a/packages/react-core/src/components/Pagination/Pagination.tsx +++ b/packages/react-core/src/components/Pagination/Pagination.tsx @@ -177,7 +177,6 @@ const handleInputWidth = (lastPage: number, node: HTMLDivElement) => { } }; -let paginationId = 0; export class Pagination extends React.Component { static displayName = 'Pagination'; paginationRef = React.createRef(); @@ -211,7 +210,7 @@ export class Pagination extends React.Component undefined, onPerPageSelect: () => undefined, onFirstClick: () => undefined, @@ -319,7 +318,7 @@ export class Pagination extends React.Component @@ -356,7 +355,7 @@ export class Pagination extends React.Component { const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); + + test('should not update generated options menu id on rerenders', () => { + const { rerender } = render(); + const id = screen.getByLabelText("test label").getAttribute("id"); + rerender(); + expect(screen.getByLabelText("test label")).toHaveAttribute("id", id); + }); }); describe('API', () => { diff --git a/packages/react-core/src/components/Pagination/__tests__/__snapshots__/Pagination.test.tsx.snap b/packages/react-core/src/components/Pagination/__tests__/__snapshots__/Pagination.test.tsx.snap index a89f6ec9472..cab728b9004 100644 --- a/packages/react-core/src/components/Pagination/__tests__/__snapshots__/Pagination.test.tsx.snap +++ b/packages/react-core/src/components/Pagination/__tests__/__snapshots__/Pagination.test.tsx.snap @@ -7,7 +7,7 @@ exports[`Pagination component render custom pagination toggle 1`] = ` data-ouia-component-id="OUIA-Generated-Pagination-top-12" data-ouia-component-type="PF4/Pagination" data-ouia-safe="true" - id="pagination-options-menu-13" + id="options-menu-top-pagination" style="--pf-c-pagination__nav-page-select--c-form-control--width-chars: 2;" >
{ { perPage={perPage} page={page} onSetPage={onSetPage} - widgetId="pagination-options-menu-top" + widgetId="compact-example" onPerPageSelect={onPerPageSelect} isCompact /> diff --git a/packages/react-core/src/components/Pagination/examples/PaginationDisabled.tsx b/packages/react-core/src/components/Pagination/examples/PaginationDisabled.tsx index a105a8d2d98..4073a9c2d8a 100644 --- a/packages/react-core/src/components/Pagination/examples/PaginationDisabled.tsx +++ b/packages/react-core/src/components/Pagination/examples/PaginationDisabled.tsx @@ -25,7 +25,7 @@ export const PaginationDisabled: React.FunctionComponent = () => { perPage={perPage} page={page} onSetPage={onSetPage} - widgetId="pagination-options-menu-top" + widgetId="disabled-example" onPerPageSelect={onPerPageSelect} isDisabled /> diff --git a/packages/react-core/src/components/Pagination/examples/PaginationIndeterminate.tsx b/packages/react-core/src/components/Pagination/examples/PaginationIndeterminate.tsx index 6b26fd0ac0d..e12a96aae61 100644 --- a/packages/react-core/src/components/Pagination/examples/PaginationIndeterminate.tsx +++ b/packages/react-core/src/components/Pagination/examples/PaginationIndeterminate.tsx @@ -30,7 +30,7 @@ export const PaginationIndeterminate: React.FunctionComponent = () => { many )} - widgetId="pagination-indeterminate" + widgetId="indeterminate-example" perPage={perPage} page={page} onSetPage={onSetPage} diff --git a/packages/react-core/src/components/Pagination/examples/PaginationNoItems.tsx b/packages/react-core/src/components/Pagination/examples/PaginationNoItems.tsx index 0b4fa6f94c8..d2a6157fb8b 100644 --- a/packages/react-core/src/components/Pagination/examples/PaginationNoItems.tsx +++ b/packages/react-core/src/components/Pagination/examples/PaginationNoItems.tsx @@ -25,7 +25,7 @@ export const PaginationNoItems: React.FunctionComponent = () => { perPage={perPage} page={page} onSetPage={onSetPage} - widgetId="pagination-options-menu-top" + widgetId="no-items-example" onPerPageSelect={onPerPageSelect} /> ); diff --git a/packages/react-core/src/components/Pagination/examples/PaginationOnePage.tsx b/packages/react-core/src/components/Pagination/examples/PaginationOnePage.tsx index ed8d11569e8..b1a7c94e903 100644 --- a/packages/react-core/src/components/Pagination/examples/PaginationOnePage.tsx +++ b/packages/react-core/src/components/Pagination/examples/PaginationOnePage.tsx @@ -25,7 +25,7 @@ export const PaginationOnePage: React.FunctionComponent = () => { perPage={perPage} page={page} onSetPage={onSetPage} - widgetId="pagination-options-menu-top" + widgetId="one-page-example" onPerPageSelect={onPerPageSelect} /> ); diff --git a/packages/react-core/src/components/Pagination/examples/PaginationSticky.tsx b/packages/react-core/src/components/Pagination/examples/PaginationSticky.tsx index 45affd06b1d..b5b32552647 100644 --- a/packages/react-core/src/components/Pagination/examples/PaginationSticky.tsx +++ b/packages/react-core/src/components/Pagination/examples/PaginationSticky.tsx @@ -33,7 +33,7 @@ export const PaginationSticky: React.FunctionComponent = () => { perPage={perPage} page={page} onSetPage={onSetPage} - widgetId="pagination-options-menu-top" + widgetId="sticky-example" onPerPageSelect={onPerPageSelect} isSticky > diff --git a/packages/react-core/src/components/Pagination/examples/PaginationTop.tsx b/packages/react-core/src/components/Pagination/examples/PaginationTop.tsx index fdd3c7891d3..3ff580ece15 100644 --- a/packages/react-core/src/components/Pagination/examples/PaginationTop.tsx +++ b/packages/react-core/src/components/Pagination/examples/PaginationTop.tsx @@ -25,7 +25,7 @@ export const PaginationTop: React.FunctionComponent = () => { perPage={perPage} page={page} onSetPage={onSetPage} - widgetId="pagination-options-menu-top" + widgetId="top-example" onPerPageSelect={onPerPageSelect} /> ); diff --git a/packages/react-table/src/docs/demos/table-demos/ColumnManagement.jsx b/packages/react-table/src/docs/demos/table-demos/ColumnManagement.jsx index 8a883f8c32a..518e6bbb777 100644 --- a/packages/react-table/src/docs/demos/table-demos/ColumnManagement.jsx +++ b/packages/react-table/src/docs/demos/table-demos/ColumnManagement.jsx @@ -425,7 +425,7 @@ export const ColumnManagementAction = () => { - {renderPagination()} + {renderPagination(PaginationVariant.top)} @@ -476,7 +476,7 @@ export const ColumnManagementAction = () => { ))} - {renderPagination()} + {renderPagination(PaginationVariant.bottom)} {renderModal()}