Skip to content
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

fix(Pagination): Use anchor instead of button for disabled prev/next controls #4951

Merged
Show file tree
Hide file tree
Changes from 4 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 .changeset/friendly-boats-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": minor
---

fix(Pagination): Use anchor instead of button for disabled prev/next controls
13 changes: 5 additions & 8 deletions packages/react/src/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,11 @@ const Page = styled.a`

&[aria-disabled],
&[aria-disabled]:hover {
color: ${get('colors.primer.fg.disabled')}; // check
cursor: default;
background-color: transparent;
border-color: transparent;
font-size: inherit;
font-family: inherit;
padding-top: inherit;
padding-bottom: inherit;
margin: 0 2px;

&:first-child {
margin-right: 6px;
}
Comment on lines +79 to +83
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to do this to enforce no visual regressions when changing from button to anchor to account for the 2px border all buttons have. Couldn't find a mapping in the theme spaces but happy to do this differently if there's a better alternative!

}

&[aria-disabled],
Expand Down
7 changes: 5 additions & 2 deletions packages/react/src/Pagination/model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,14 @@ export function buildComponentData(
key = 'page-prev'
content = 'Previous'
if (page.disabled) {
Object.assign(props, {as: 'button', 'aria-disabled': 'true'})
Object.assign(props, {'aria-disabled': 'true'})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add role="link" here, since I believe we'd only need it when the link is disabled. This should allow us to remove it below in the else condition

} else {
Object.assign(props, {
rel: 'prev',
href: hrefBuilder(page.num),
'aria-label': 'Previous Page',
onClick,
role: 'link',
})
}
break
Expand All @@ -163,13 +164,14 @@ export function buildComponentData(
key = 'page-next'
content = 'Next'
if (page.disabled) {
Object.assign(props, {as: 'button', 'aria-disabled': 'true'})
Object.assign(props, {'aria-disabled': 'true'})
} else {
Object.assign(props, {
rel: 'next',
href: hrefBuilder(page.num),
'aria-label': 'Next Page',
onClick,
role: 'link',
})
}
break
Expand All @@ -185,6 +187,7 @@ export function buildComponentData(
'aria-label': `Page ${page.num}${page.precedesBreak ? '...' : ''}`,
onClick,
'aria-current': page.selected ? 'page' : undefined,
role: 'link',
})
break
}
Expand Down
Loading