Skip to content

Commit

Permalink
Add aria-labelledby (#164)
Browse files Browse the repository at this point in the history
Co-authored-by: Rogin Farrer <rfarrer@wayfair.com>
  • Loading branch information
roginfarrer and Rogin Farrer committed Nov 15, 2023
1 parent 6d4965c commit cc68b19
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/tricky-feet-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-collapsed': patch
---

Added `aria-labelledby` to the collapse panel, to be labelled by the toggle.
1 change: 1 addition & 0 deletions packages/react-collapsed/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ export function useCollapse({
return {
id: `react-collapsed-panel-${uniqueId}`,
'aria-hidden': !isExpanded,
'aria-labelledby': `react-collapsed-toggle-${uniqueId}`,
role: 'region',
...args,
[refKey || 'ref']: mergeRefs(collapseElRef, theirRef),
Expand Down
5 changes: 5 additions & 0 deletions packages/react-collapsed/tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,8 @@ test('id will be overridden by prop getters', () => {
expect(container.querySelector('#baz')).toBeInTheDocument()
expect(container.querySelector('#bar')).toBeInTheDocument()
})

test('collapse element labelled by toggle', () => {
render(<Collapse />)
expect(screen.getByLabelText('Toggle')).toEqual(screen.getByTestId('collapse'))
})

0 comments on commit cc68b19

Please sign in to comment.