Skip to content

Fix ActionList group roles #1851

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

Closed
wants to merge 18 commits into from
Closed
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/drafts-actionlist-group-roles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Better aria roles for ActionList group
5 changes: 5 additions & 0 deletions .changeset/drafts-dropdownmenu2-merged-into-actionmenu2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Merges drafts/DropdownMenu2 into drafts/ActionMenu2
45 changes: 38 additions & 7 deletions docs/content/drafts/ActionMenu2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,44 @@ You can choose to have a different _anchor_ for the Menu dependending on the app
</ActionMenu>
```

### With Selection

Use `selectionVariant` on `ActionList` to create a menu with single or multiple selection.

```javascript live noinline drafts
const fieldTypes = [
{icon: TypographyIcon, name: 'Text'},
{icon: NumberIcon, name: 'Number'},
{icon: CalendarIcon, name: 'Date'},
{icon: SingleSelectIcon, name: 'Single select'},
{icon: IterationsIcon, name: 'Iteration'}
]

const Example = () => {
const [selectedIndex, setSelectedIndex] = React.useState(1)
const selectedType = fieldTypes[selectedIndex]

return (
<ActionMenu>
<ActionMenu.Button aria-label="Select field type" leadingIcon={selectedType.icon}>
{selectedType.name}
</ActionMenu.Button>
<ActionMenu.Overlay width="medium">
<ActionList selectionVariant="single">
{fieldTypes.map((type, index) => (
<ActionList.Item key={index} selected={index === selectedIndex} onSelect={() => setSelectedIndex(index)}>
<type.icon /> {type.name}
</ActionList.Item>
))}
</ActionList>
</ActionMenu.Overlay>
</ActionMenu>
)
}

render(<Example />)
```

### 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`. Make sure you add `aria-expanded` and `aria-haspopup` to the external anchor:
Expand Down Expand Up @@ -241,12 +279,6 @@ render(
)
```

<Note variant="warning">

Use `ActionMenu` to choose an action from a list. If you’re looking for single or multiple selection, use [DropdownMenu](/DropdownMenu) or [SelectPanel](/SelectPanel) instead.

</Note>

## Props / API reference

### ActionMenu
Expand Down Expand Up @@ -305,6 +337,5 @@ Use `ActionMenu` to choose an action from a list. If you’re looking for single
## Related components

- [ActionList](/drafts/ActionList2)
- [DropdownMenu](/DropdownMenu)
- [SelectPanel](/SelectPanel)
- [Button](/drafts/Button2)
Loading