Skip to content

Commit b604403

Browse files
authored
AnchoredOverlay: Add aria-expanded to anchor (#1758)
* add aria-expanded to the menu button * add changeset * update snapshots
1 parent 6e44d78 commit b604403

File tree

9 files changed

+15
-3
lines changed

9 files changed

+15
-3
lines changed
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+
ActionMenu v2: Add aria-expanded to the ActionMenu.Button

docs/content/drafts/ActionMenu2.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ render(
192192

193193
### With External Anchor
194194

195-
To create an anchor outside of the menu, you need to switch to controlled mode for the menu and pass it as `anchorRef` to `ActionMenu`:
195+
To create an anchor outside of the menu, you need to switch to controlled mode for the menu and pass it as `anchorRef` to `ActionMenu`. Make sure you add `aria-expanded` and `aria-haspopup` to the external anchor:
196196

197197
```javascript live noinline
198198
// import {ActionMenu, ActionList} from '@primer/react/drafts'
@@ -204,7 +204,7 @@ const Example = () => {
204204

205205
return (
206206
<>
207-
<Button ref={anchorRef} onClick={() => setOpen(!open)}>
207+
<Button ref={anchorRef} aria-haspopup="true" aria-expanded={open} onClick={() => setOpen(!open)}>
208208
{open ? 'Close Menu' : 'Open Menu'}
209209
</Button>
210210

src/AnchoredOverlay/AnchoredOverlay.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export const AnchoredOverlay: React.FC<AnchoredOverlayProps> = ({
156156
id: anchorId,
157157
'aria-labelledby': anchorId,
158158
'aria-haspopup': 'true',
159+
'aria-expanded': open,
159160
tabIndex: 0,
160161
onClick: onAnchorClick,
161162
onKeyDown: onAnchorKeyDown

src/__tests__/__snapshots__/ActionMenu.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ exports[`ActionMenu renders consistently 1`] = `
6868
}
6969
7070
<button
71+
aria-expanded={false}
7172
aria-haspopup="true"
7273
aria-label="menu"
7374
aria-labelledby="react-aria-1"

src/__tests__/__snapshots__/ActionMenu2.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ exports[`ActionMenu renders consistently 1`] = `
8080
fontFamily="normal"
8181
>
8282
<button
83+
aria-expanded={false}
8384
aria-haspopup="true"
8485
aria-labelledby="react-aria-1"
8586
className="c1"

src/__tests__/__snapshots__/AnchoredOverlay.test.tsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ exports[`AnchoredOverlay renders consistently 1`] = `
8080
fontFamily="normal"
8181
>
8282
<button
83+
aria-expanded={false}
8384
aria-haspopup="true"
8485
aria-labelledby="react-aria-1"
8586
className="c1"
@@ -193,6 +194,7 @@ exports[`AnchoredOverlay should render consistently when open 1`] = `
193194
font-family="normal"
194195
>
195196
<button
197+
aria-expanded="true"
196198
aria-haspopup="true"
197199
aria-labelledby="react-aria-1"
198200
class="c1"

src/__tests__/__snapshots__/DropdownMenu.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ exports[`DropdownMenu renders consistently 1`] = `
7272
}
7373
7474
<button
75+
aria-expanded={false}
7576
aria-haspopup="true"
7677
aria-labelledby="react-aria-1"
7778
className="c0"

src/__tests__/__snapshots__/SelectPanel.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ exports[`SelectPanel renders consistently 1`] = `
8484
fontFamily="normal"
8585
>
8686
<button
87+
aria-expanded={false}
8788
aria-haspopup="true"
8889
aria-labelledby="react-aria-1"
8990
className="c1"

src/stories/ActionMenu2.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export function ExternalAnchor(): JSX.Element {
137137
<h2>External Open State: {open ? 'Open' : 'Closed'}</h2>
138138
<h2>Last option activated: {actionFired}</h2>
139139
<div>
140-
<Button ref={anchorRef} onClick={() => setOpen(!open)}>
140+
<Button ref={anchorRef} onClick={() => setOpen(!open)} aria-expanded={open} aria-haspopup="true">
141141
{open ? 'Close Menu' : 'Open Menu'}
142142
</Button>
143143
</div>

0 commit comments

Comments
 (0)