Action Menu
This versatile menu can be used in combination with buttons which may offer multiple contextual actions (e.g. save, export). The menu is typically as wide as the longest item in the menu and at least as wide as the button that triggers it.
To save space and group options, use an Action menu in combination with a button to render a list of actions. You can also use an Action menu to show a list of different options for the same action. For example, an export button can open an Action menu with a list of file formats.
The trigger for a Action menu is another component, usually a Button.
Example
note
If ESLint's react/jsx-key
rule is active make sure to set a key on the menu items!
Usage Rules
Do:
- Group menu items that belong to a context inside an Action menu
- Use short and clear labels. Keep it between one to three words
- Use a line to separate destructive items (e.g. delete) from the others or to group similar items
Don't:
- Use an ActionMenu if it would only contain one item
- Mix menu items with and without icons in the same group
- Mix menu items with and without descriptions in the same group
Variants
Data-testid
You can use the dataTestId
prop to access data-testid
for the action menu items and submenu items.
Description
Menu items can have a description with further information about the action
Disabled
You can disable Menu item by setting the disabled
property to true
.
Grouping
The item with divider
type can be used to visually group Menu items.
You can specify a label for the group by providing the label
property. This will visually assign the next following menu items to a group with a provided label.
Icons
Menu items can have an Icon next to label to emphasize an action. All available icons can be found here.
Item Checkbox
The item with checkbox
type can be used as a checkbox. You can use the property isSelected
to set the checked state of item.
Item Link
The item with link
type can be used as a link. You can also specify a href with to
property. An <a>
with a href
attribute will be rendered by default but this can be changed using the as
property.
Offset
The prop offset
lets you displace a menu element from its reference element. The default value is [0, 4].
Open trigger
As the default, Action menu is opened by clicking. But it is also opened by hovering with prop isHoverOpen
.
Open state
You can update the open state manually by using the isOpen
and setIsOpen
props.
Submenu
To group related menu items a submenu can be provided.
Top level menu items have an additional submenuItems
property which takes a list of menu items.
Please note that there can only be one level of submenus.
Placement
We also have support for placing the menu, can be accessed using placement
prop, default to bottom-start
.
Props
ActionMenu
Name | Type | Default |
---|---|---|
items * Array of menu items. See the structure of the ItemType |
| — |
children Trigger for the menu.
Ensure that the element looks like it can be clicked and that it's focusable (e.g. a Button ) |
| — |
disabled if true menu will not open |
| false |
isOpen Open state, if true menu will open |
| — |
onShow The callback will be executed after the menu has opened |
| — |
onHide The callback will be executed after the menu has closed |
| — |
placement The menu placement relatively to the trigger element |
| — |
setIsOpen The callback that allows to set open state e.g. when clicking on trigger element |
| — |
isHoverOpen The prop that allows to open by hovering on the element |
| false |
offset Allows to displace a menu element from its reference element. |
| — |
css Add custom styles to this component. Use with caution. Learn more here: Link |
| — |
inputFieldCss |
| — |
data-{foo} Data attributes can be used by testing libraries to retrieve components or assert their existence |
| — |
* - the prop is required. |
Structure of the MenuItemType
interface
Name | Type | Default |
---|---|---|
formatMenuItem |
| — |
hoverDisabled Whether a different style should not be applied on hover |
| — |
iconName Name of the Icon that would appear on the right. Please refer to the full list of icons here: Link | "AddValue" | "AppGrid" | "ArrowCircleLeft" | "ArrowCircleRight" | "ArrowDown" | "ArrowDownLeft" | "A... | — |
label Label of the menu item |
| — |
description In case the label is not sufficient you can add a short description |
| — |
onClick This handler will be called if the menu item is pressed (either through click or keyboard events) |
| — |
disabled Use this prop if the item should not be interactive |
| false |
indentOnRight If set Check icon will be positioned on the right. Internal use only! |
| false |
dataTestId A test id to be used by testing libraries. It will be added as a "data-testid" attribute on the root of the menu item |
| — |
type Dividing items show a separating line and can be used to form menu item groups.
submenu items can be used to display a submenu.
Note that these types of items cannot be clicked. |
| "item" |
* - the prop is required. |
Structure of the SubmenuItemType
interface
Name | Type | Default |
---|---|---|
itemIndex * |
| — |
hideSubmenu * |
| — |
submenuItems Array of submenu items |
| — |
iconName Name of the Icon that would appear on the right. Please refer to the full list of icons here: Link | "AddValue" | "AppGrid" | "ArrowCircleLeft" | "ArrowCircleRight" | "ArrowDown" | "ArrowDownLeft" | "A... | — |
label Label of the menu item |
| — |
description In case the label is not sufficient you can add a short description |
| — |
onClick This handler will be called if the menu item is pressed (either through click or keyboard events) |
| — |
disabled Use this prop if the item should not be interactive |
| false |
dataTestId A test id to be used by testing libraries. It will be added as a "data-testid" attribute on the root of the menu item |
| — |
type Dividing items show a separating line and can be used to form menu item groups.
submenu items can be used to display a submenu.
Note that these types of items cannot be clicked. |
| — |
* - the prop is required. |