Skip to content

Commit 5ffdc40

Browse files
joebuonoJoe Buono
andauthored
fix(ui-react): Pagination current item a11y (#2336)
* change Flex to render as button, add aria-current attribute * update test * Create eighty-snails-push.md * small change to currentPageLabel * update docs * updated unit test * change aria-current to 'page', remove irrelevant comment * update test Co-authored-by: Joe Buono <[email protected]>
1 parent f067420 commit 5ffdc40

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

.changeset/eighty-snails-push.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@aws-amplify/ui-react": patch
3+
---
4+
5+
fix(ui-react): Improve accessibility of Pagination current item button

docs/src/pages/[platform]/components/pagination/react.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Use the following props to customize these labels:
9292

9393
- **`nextLabel`**: Set the `aria-label` for the next page button (defaults to `Go to next page`)
9494

95-
- **`currentPageLabel`**: Set the `VisuallyHidden` label for current page (defaults to `Current Page:`). This will be used to construct the label text for current page. e.g, `Current Page: 1` if page `1` is the current page.
95+
- **`currentPageLabel`**: Set the `VisuallyHidden` label for current page (defaults to `Page`). This will be used to construct the label text for current page. e.g, `Page: 1` if page `1` is the current page.
9696

9797
- **`pageLabel`**: Set the label for each page button other than the current page (defaults to `Go to page`). This will be used to construct the `aria-label`. e.g, `Go to page 1` for page `1` button.
9898

packages/react/src/primitives/Pagination/PaginationItem.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,13 @@ export const PaginationItem: React.FC<PaginationItemProps> = ({
6060
<View as="li">
6161
{page === currentPage ? (
6262
<Flex
63-
as="span"
63+
aria-current="page"
64+
as="button"
6465
className={ComponentClassNames.PaginationItemCurrent}
6566
testId={PAGINATION_CURRENT_TEST_ID}
6667
{...rest}
6768
>
68-
{/**
69-
* Use markup to indicate the current item of a menu, such as the current page on a website, to improve orientation in the menu.
70-
* @link https://www.w3.org/WAI/tutorials/menus/structure/#indicate-the-current-item
71-
*/}
72-
<VisuallyHidden>{currentPageLabel}</VisuallyHidden>
69+
<VisuallyHidden>{currentPageLabel}:</VisuallyHidden>
7370
{page}
7471
</Flex>
7572
) : (

packages/react/src/primitives/Pagination/__tests__/Pagination.test.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,13 @@ describe('Pagination component: ', () => {
328328
/>
329329
);
330330
const pageItem = await screen.findByText('1');
331-
expect(pageItem.nodeName).toBe('SPAN');
331+
expect(pageItem.nodeName).toBe('BUTTON');
332332
expect(pageItem).toHaveClass(ComponentClassNames.PaginationItemCurrent);
333333
const invisibleLabel = await screen.findByText(
334-
ComponentText.PaginationItem.currentPageLabel
334+
`${ComponentText.PaginationItem.currentPageLabel}:`
335335
);
336336
expect(invisibleLabel).toHaveClass(ComponentClassNames.VisuallyHidden);
337+
expect(pageItem.getAttribute('aria-current')).toBe('page');
337338

338339
userEvent.click(pageItem);
339340
expect(mockOnClick).not.toHaveBeenCalled();
@@ -353,6 +354,7 @@ describe('Pagination component: ', () => {
353354
);
354355
expect(previous.nodeName).toBe('BUTTON');
355356
expect(previous).not.toBeDisabled();
357+
expect(previous.getAttribute('aria-current')).toBe(null);
356358
userEvent.click(previous);
357359
expect(mockOnClick).toHaveBeenCalledTimes(1);
358360
expect(mockOnClick).toHaveBeenCalledWith();
@@ -367,12 +369,14 @@ describe('Pagination component: ', () => {
367369
onClick={mockOnClick}
368370
/>
369371
);
370-
const previous = await screen.findByLabelText(
372+
const next = await screen.findByLabelText(
371373
ComponentText.PaginationItem.nextLabel
372374
);
373-
expect(previous.nodeName).toBe('BUTTON');
374-
expect(previous).not.toBeDisabled();
375-
userEvent.click(previous);
375+
expect(next.nodeName).toBe('BUTTON');
376+
expect(next).not.toBeDisabled();
377+
expect(next.getAttribute('aria-current')).toBe(null);
378+
379+
userEvent.click(next);
376380
expect(mockOnClick).toHaveBeenCalledTimes(1);
377381
expect(mockOnClick).toHaveBeenCalledWith();
378382
});

packages/react/src/primitives/shared/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ export const ComponentText = {
661661
clearButtonLabel: 'Clear input',
662662
},
663663
PaginationItem: {
664-
currentPageLabel: 'Current Page:',
664+
currentPageLabel: 'Page',
665665
nextLabel: 'Go to next page',
666666
pageLabel: 'Go to page',
667667
previousLabel: 'Go to previous page',

0 commit comments

Comments
 (0)