Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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/actionmenu2-aria-expanded.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

ActionMenu v2: Add aria-expanded to the ActionMenu.Button
4 changes: 2 additions & 2 deletions docs/content/drafts/ActionMenu2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ render(

### With External Anchor

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`:
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:

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

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

Expand Down
1 change: 1 addition & 0 deletions src/AnchoredOverlay/AnchoredOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export const AnchoredOverlay: React.FC<AnchoredOverlayProps> = ({
id: anchorId,
'aria-labelledby': anchorId,
'aria-haspopup': 'true',
'aria-expanded': open,
tabIndex: 0,
onClick: onAnchorClick,
onKeyDown: onAnchorKeyDown
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/__snapshots__/ActionMenu.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ exports[`ActionMenu renders consistently 1`] = `
}

<button
aria-expanded={false}
aria-haspopup="true"
aria-label="menu"
aria-labelledby="react-aria-1"
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/__snapshots__/ActionMenu2.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ exports[`ActionMenu renders consistently 1`] = `
fontFamily="normal"
>
<button
aria-expanded={false}
aria-haspopup="true"
aria-labelledby="react-aria-1"
className="c1"
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/__snapshots__/AnchoredOverlay.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ exports[`AnchoredOverlay renders consistently 1`] = `
fontFamily="normal"
>
<button
aria-expanded={false}
aria-haspopup="true"
aria-labelledby="react-aria-1"
className="c1"
Expand Down Expand Up @@ -193,6 +194,7 @@ exports[`AnchoredOverlay should render consistently when open 1`] = `
font-family="normal"
>
<button
aria-expanded="true"
Copy link
Contributor

Choose a reason for hiding this comment

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

Wierd that this is a string though

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah!

the types are accepts both, so that's nice

'aria-expanded'?: boolean | 'false' | 'true'; ref: @types/react

aria-haspopup="true"
aria-labelledby="react-aria-1"
class="c1"
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/__snapshots__/DropdownMenu.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ exports[`DropdownMenu renders consistently 1`] = `
}

<button
aria-expanded={false}
aria-haspopup="true"
aria-labelledby="react-aria-1"
className="c0"
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/__snapshots__/SelectPanel.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ exports[`SelectPanel renders consistently 1`] = `
fontFamily="normal"
>
<button
aria-expanded={false}
aria-haspopup="true"
aria-labelledby="react-aria-1"
className="c1"
Expand Down
2 changes: 1 addition & 1 deletion src/stories/ActionMenu2.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function ExternalAnchor(): JSX.Element {
<h2>External Open State: {open ? 'Open' : 'Closed'}</h2>
<h2>Last option activated: {actionFired}</h2>
<div>
<Button ref={anchorRef} onClick={() => setOpen(!open)}>
<Button ref={anchorRef} onClick={() => setOpen(!open)} aria-expanded={open} aria-haspopup="true">
{open ? 'Close Menu' : 'Open Menu'}
</Button>
</div>
Expand Down