Skip to content

Add required paginationLabel prop to TablePagination component's use of Pagination component. #3406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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