On this page
ActionMenu (legacy)
- Deprecated
- Not reviewed for accessibility
On this page
An ActionMenu
is an ActionList-based component for creating a menu of actions that expands through a trigger button.
Deprecation
Use new version of ActionMenu with composable API, design updates and accessibility fixes.
Before
<ActionMenuanchorContent="Menu"onAction={fn}items={[{text: 'New file'},{text: 'Copy link'},{text: 'Edit file'},ActionMenu.Divider,{text: 'Delete file', variant: 'danger'},]}overlayProps={{width: 'small'}}/>
After
<ActionMenu><ActionMenu.Button>Menu</ActionMenu.Button><ActionMenu.Overlay width="small"><ActionList><ActionList.Item onSelect={fn}>New file</ActionList.Item><ActionList.Item>Copy link</ActionList.Item><ActionList.Item>Edit file</ActionList.Item><ActionList.Divider /><ActionList.Item variant="danger">Delete file</ActionList.Item></ActionList></ActionMenu.Overlay></ActionMenu>
Or continue using deprecated API:
import {ActionMenu} from '@primer/react/deprecated'
Default example
Example with grouped items
Component props
Name | Type | Default | Description |
---|---|---|---|
items | ItemProps[] | undefined | Required. A list of item objects conforming to the ActionList.Item props interface. |
renderItem | (props: ItemProps) => JSX.Element | ActionList.Item | Optional. If defined, each item in items will be passed to this function, allowing for ActionList -wide custom item rendering. |
groupMetadata | GroupProps[] | undefined | Optional. If defined, ActionList will group items into ActionList.Group s separated by ActionList.Divider according to their groupId property. |
renderAnchor | (props: ButtonProps) => JSX.Element | Button | Optional. If defined, provided component will be used to render the menu anchor. Will receive the selected Item text as children prop when an item is activated. |
anchorContent | React.ReactNode | undefined | Optional. If defined, it will be passed to the trigger as the elements child. |
onAction | (props: ItemProps) => void | undefined | Optional. If defined, this function will be called when a menu item is activated either by a click or a keyboard press. |
open | boolean | undefined | Optional. If defined, ActionMenu will use this to control the open/closed state of the Overlay instead of controlling the state internally. Should be used in conjunction with the setOpen prop. |
setOpen | (state: boolean) => void | undefined | Optional. If defined, ActionMenu will use this to control the open/closed state of the Overlay instead of controlling the state internally. Should be used in conjunction with the open prop. |