Skip to content

Commit

Permalink
Remove aria-label from AnchorNav toggle button in favour of visually-…
Browse files Browse the repository at this point in the history
…hidden text (#841)

* remove aria-label from AnchorNav toggle button in favour of visually-hidden text

* fix failing test

* move space inside span

* add changeset
  • Loading branch information
joshfarrant authored Dec 2, 2024
1 parent c492b04 commit 78e82c1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/kind-comics-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react-brand': patch
---

Improved accessibility in `AnchorNav` through clearer navigation menu labelling for screen reader users on narrow viewports.
2 changes: 0 additions & 2 deletions packages/react/src/AnchorNav/AnchorNav.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,10 @@ describe('AnchorNav', () => {
const {getByTestId} = render(<MockAnchorNavFixture />)
const menuButton = getByTestId(AnchorNav.testIds.menuButton)

expect(menuButton).toHaveAttribute('aria-label', 'open anchor navigation menu') // aria label before menu open
expect(menuButton).toHaveAttribute('aria-expanded', 'false') // aria attribute before menu open

fireEvent.click(menuButton) // toggle menu button

expect(menuButton).toHaveAttribute('aria-label', 'close anchor navigation menu') // aria label after menu open
expect(menuButton).toHaveAttribute('aria-expanded', 'true') // aria attribute before menu open
})

Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/AnchorNav/AnchorNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,16 @@ function _AnchorNav({children, enableDefaultBgColor = false, hideUntilSticky = f
<button
onClick={handleMenuToggle}
className={clsx(styles['AnchorNav-menu-button'])}
aria-expanded={menuOpen ? 'true' : 'false'}
aria-expanded={menuOpen}
aria-controls={idForLinkContainer}
aria-label={`${menuOpen ? 'close' : 'open'} anchor navigation menu`}
data-testid={testIds.menuButton}
>
{menuOpen ? (
<ChevronUpIcon size={16} className={styles['AnchorNav-menu-button-arrow']} fill="currentcolor" />
) : (
<ChevronDownIcon size={16} className={styles['AnchorNav-menu-button-arrow']} fill="currentcolor" />
)}
<span className="visually-hidden">Anchor navigation menu. Currently selected: </span>
<Text as="span" className={clsx(styles['AnchorNav-link-label'])}>
{currentActiveNavItem}
</Text>
Expand Down

0 comments on commit 78e82c1

Please sign in to comment.