Skip to content

Commit

Permalink
fix: add required paginationLabel prop to TablePagination component's…
Browse files Browse the repository at this point in the history
… use of Pagination component (#3406)

This commit fixes a bug with the TablePagination component. This component renders the Pagination component without a paginationLabel prop, which is a required prop of the Pagination component. This commit adds a paginationLabel="table pagination" prop, which matches the prop passed to the PaginationComponent by the TablePaginationMinimal component.

Authored-by: michaelroytman <mroytman@edx.org>
  • Loading branch information
adamstankiewicz authored Jan 31, 2025
1 parent c0aa4c7 commit b0187dd
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/DataTable/TablePagination.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import React, { useContext } from 'react';
import { useIntl } from 'react-intl';
import DataTableContext from './DataTableContext';
import Pagination from '../Pagination';
import messages from './messages';

function TablePagination() {
const intl = useIntl();

const {
pageCount, state, gotoPage,
} = useContext(DataTableContext);
Expand All @@ -19,6 +23,7 @@ function TablePagination() {
currentPage={pageIndex + 1}
onPageSelect={(pageNum) => gotoPage(pageNum - 1)}
pageCount={pageCount}
paginationLabel={intl.formatMessage(messages.paginationLabel)}
icons={{
leftIcon: null,
rightIcon: null,
Expand Down
6 changes: 5 additions & 1 deletion src/DataTable/TablePaginationMinimal.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import React, { useContext } from 'react';
import { useIntl } from 'react-intl';
import DataTableContext from './DataTableContext';
import Pagination from '../Pagination';
import { ArrowBackIos, ArrowForwardIos } from '../../icons';
import messages from './messages';

function TablePaginationMinimal() {
const intl = useIntl();

const {
nextPage, pageCount, gotoPage, state,
} = useContext(DataTableContext);
Expand All @@ -20,7 +24,7 @@ function TablePaginationMinimal() {
variant="minimal"
currentPage={pageIndex + 1}
pageCount={pageCount}
paginationLabel="table pagination"
paginationLabel={intl.formatMessage(messages.paginationLabel)}
onPageSelect={(pageNum) => gotoPage(pageNum - 1)}
icons={{
leftIcon: ArrowBackIos,
Expand Down
11 changes: 11 additions & 0 deletions src/DataTable/messages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineMessages } from 'react-intl';

const messages = defineMessages({
paginationLabel: {
id: 'pgn.DataTable.paginationLabel',
defaultMessage: 'table pagination',
description: 'Accessibile name for the navigation element of a pagination component',
},
});

export default messages;
6 changes: 5 additions & 1 deletion src/DataTable/tests/TableFooter.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ describe('<TableFooter />', () => {
it('Renders the default footer', () => {
render(<TableFooterWrapper />);
expect(screen.getByTestId('row-status')).toBeInTheDocument();
expect(screen.getByLabelText('table pagination')).toBeInTheDocument();

// The TableFooter contains two components that have the aria-label
// "table pagination" - DataTable and DataTableMinimal.
const tables = screen.getAllByLabelText('table pagination');
tables.forEach(table => expect(table).toBeInTheDocument());
});

it('accepts a class name', () => {
Expand Down
9 changes: 6 additions & 3 deletions src/DataTable/tests/TablePagination.test.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { render, act, screen } from '@testing-library/react';
import { IntlProvider } from 'react-intl';
import userEvent from '@testing-library/user-event';

import TablePagination from '../TablePagination';
Expand All @@ -14,9 +15,11 @@ const instance = {
// eslint-disable-next-line react/prop-types
function PaginationWrapper({ value }) {
return (
<DataTableContext.Provider value={value}>
<TablePagination />
</DataTableContext.Provider>
<IntlProvider>
<DataTableContext.Provider value={value}>
<TablePagination />
</DataTableContext.Provider>
</IntlProvider>
);
}

Expand Down

0 comments on commit b0187dd

Please sign in to comment.