Skip to content

Commit e352e19

Browse files
authored
Pagination: Accessibility enhancements (#5488)
* Make default Pagination story interactive * Hide Pagination Previous and Next buttons from the a11y tree * Add changeset
1 parent b584e86 commit e352e19

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

.changeset/eighty-carpets-rush.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": patch
3+
---
4+
5+
Pagination: Hides the `Pagination` Previous and Next buttons from the accessibility tree when they are disabled.

packages/react/src/Pagination/Pagination.stories.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react'
1+
import React, {useState} from 'react'
22
import type {Meta, StoryFn} from '@storybook/react'
33
import type {ComponentProps} from '../utils/types'
44
import Pagination from './Pagination'
@@ -26,9 +26,21 @@ const parseShowPagesArg = (value: boolean | string) => {
2626
}
2727
}
2828

29-
export const Default = () => (
30-
<Pagination pageCount={15} currentPage={2} onPageChange={e => e.preventDefault()} showPages={{narrow: false}} />
31-
)
29+
export const Default = () => {
30+
const [page, setPage] = useState(2)
31+
32+
return (
33+
<Pagination
34+
pageCount={15}
35+
currentPage={page}
36+
onPageChange={(e, n) => {
37+
e.preventDefault()
38+
setPage(n)
39+
}}
40+
showPages={{narrow: false}}
41+
/>
42+
)
43+
}
3244

3345
export const Playground: StoryFn<ComponentProps<typeof Pagination>> = ({showPages, ...args}) => {
3446
return (

packages/react/src/Pagination/model.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export function buildComponentData(
148148
key = 'page-prev'
149149
content = 'Previous'
150150
if (page.disabled) {
151-
Object.assign(props, {'aria-disabled': 'true', role: 'link'})
151+
Object.assign(props, {'aria-hidden': 'true'})
152152
} else {
153153
Object.assign(props, {
154154
rel: 'prev',
@@ -163,7 +163,7 @@ export function buildComponentData(
163163
key = 'page-next'
164164
content = 'Next'
165165
if (page.disabled) {
166-
Object.assign(props, {'aria-disabled': 'true', role: 'link'})
166+
Object.assign(props, {'aria-hidden': 'true'})
167167
} else {
168168
Object.assign(props, {
169169
rel: 'next',

0 commit comments

Comments
 (0)