Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline
A lightning:buttonMenu represents a button that when clicked displays a dropdown menu of actions or functions that a user can access.
The menu closes when you click away from it, and it also closes and puts the focus back on the button when you select a menu item.
Use lightning:menuItem as a subcomponent of lightning:buttonMenu to specify the menu items for the button menu.
This component implements styling from menus in the Lightning Design System.
Customize Styling
Use the class attribute to apply utility classes. For example, you can set class="slds-m-vertical_large" or other margin classes to add spacing around the icon.
Use the variant attribute to change border styling, fill, and clickable area. See Variants for descriptions of the available variants.
Use the iconName attribute to specify an optional utility icon to display in front of the default icon. Use the iconSize attribute to change the icon size from the default size of medium.
Use the label attribute to add a text label to the button before the icon.
When applying Lightning Design System classes or icons, check that they are available in the Lightning Design System release tied to your org. The Lightning Design System site shows the latest Lightning Design System resources, and these become available only when the new release is available in your org.
This example shows a dropdown menu with some customized styling and three items.
When onselect is triggered, its event will have a value parameter, which is the value of the selected menu item. Here’s an example of how to read that value.
1handleMenuSelect: function(cmp, event, helper){2 var selectedMenuItemValue = event.getParam("value");3}
Variants
The lightning:buttonMenu component supports several variants that change the look of the button.
border - Shows a gray border around the button’s down arrow symbol. The area inside the border is transparent and clickable. This is the default variant and doesn’t need to be specified.
border-inverse - Same as the border variant except the down arrow is white so it’s visible on dark backgrounds.
border-filled - Same as the border variant, except the area inside the border is filled with white.
container - Shows only the down arrow, without a visible border. The clickable area surrounding the down arrow is the same size as the default border variant and is transparent.
bare - Same as the container variant, except the clickable area surrounding the down arrow is smaller than the default.
bare-inverse - Same as the bare variant except the down arrow is white so it’s visible on dark backgrounds.
Checked Menu Items
You can create menu items that can be checked or unchecked using the checked attribute in the lightning:menuItem component, toggling it as needed. To enable toggling of a menu item, you must set an initial value on the checked attribute, specifying either true or false.
Create Dividers and Subheadings
Use the lightning:menuDivider component to create a dividing line after a menu item.
The isLoading attribute enables you to show an activity indicator while the menu is loading. You might use this, for example, to inform users that the menu is working while generating a large list of menu items. When isLoading is true, the menu shows a spinner.
Use loadingStateAlternativeText along with isLoading to specify explanatory text such as “Loading menu…” or “Please wait while items load”.
Draft Indicators
Use the isDraft and draftAlternativeText attributes together to indicate that the button menu is in an unsaved state. The draft indicator, an asterisk, is shown for the button menu when isDraft is true. The draftAlternativeText attribute is required to provide text describing the reason the menu is considered in a draft state. The button menu draft state might be used to to show there is unsaved state or data that could be lost, for example if there’s a user change in a customizable menu.
Usage Considerations
Icons are not available in Lightning Out, but they are available in Lightning Components for Visualforce and other experiences.
This component contains menu items that are created only if the button is triggered. You won’t be able to reference the menu items during initialization or if the button isn’t triggered yet.
In Lightning Experience, a button menu that’s opened overlays the record edit page or modal, the global header, and record form footer when scrolling.
You can customize the alignment of the dropdown menu relative to the button using menuAlignment. If you are using buttonMenu in a container that specifies the overflow:hidden CSS property, setting menuAlignment="auto" ensures that the dropdown menu is not hidden from view when the menu is toggled. For mobile devices, set menuAlignment="auto" to ensure proper display of the menu.
Accessibility
To inform screen readers that a button menu is disabled, set the disabled attribute to true.
Buttons must have an accessible name to enable assistive technology to describe the button’s purpose. Provide this name using the alternativeText or label attribute. Make it a clear action, such as “Show menu”. To make the name available to assistive technology but hidden from view, use alternativeText.
lightning:buttonMenu is rendered with aria-haspopup="true" to indicate that the button opens a menu. The component also indicates whether the menu is currently expanded or collapsed using aria-expanded="true" or aria-expanded="false". To control the visibility of the menu, use the visible attribute. Note that a disabled menu cannot be expanded or collapsed.
To display a contextual popup over the button menu, use the tooltip attribute. The popup becomes visible when you hover over the button, or after the button receives keyboard focus. Showing the popup on hover or on keyboard focus ensures that all users can access it, even if they aren’t using a mouse.
If you use both title and tooltip attributes, they are both visible when you hover over the button. Some screen readers don’t support the title attribute and many of them don’t read the title attribute by default.
Attributes
Name
Description
Type
Default
Required
accesskey
Specifies a shortcut key to activate or focus an element.
String
alternativeText
The assistive text for the button.
String
body
The body of the component.
Aura.ComponentDefRef[]
class
A CSS class for the outer element, in addition to the component's base classes.
String
disabled
If true, the menu is disabled. Disabling the menu prevents users from opening it. This value defaults to false.
Boolean
false
draftAlternativeText
Describes the reason for showing the draft indicator. This is required when the isDraft attribute is true.
String
iconName
The name of the icon to be used in the format utility:down. This value defaults to utility:down. If an icon other than utility:down or utility:chevrondown is used, a utility:down icon is appended after that icon.
String
utility:down
iconSize
The size of the icon. Options include xx-small, x-small, small, medium, or large. This value defaults to medium.
String
medium
isDraft
If true, the menu trigger shows a draft indicator. This value defaults to false.
Boolean
false
isLoading
If true, the menu is in a loading state and shows a spinner. This value defaults to false.
Boolean
false
label
Optional text to be shown on the button.
String
loadingStateAlternativeText
Message displayed while the menu is in the loading state.
String
menuAlignment
Determines the alignment of the menu relative to the button. Available options are: auto, left, center, right, bottom-left, bottom-center, bottom-right. The auto option aligns the dropdown menu based on available space. This value defaults to left.
String
left
name
The name for the button element. This value is optional and can be used to identify the button in a callback.
String
onblur
The action triggered when the element releases focus.
Aura.Action
onfocus
The action triggered when the element receives focus.
Aura.Action
onopen
Action fired when the menu is opened.
Aura.Action
onselect
Action fired when a menu item is selected. The 'detail.menuItem' property of the passed event is the selected menu item.
Aura.Action
tabindex
Specifies the tab order of an element when the Tab key is used for navigating. The tabindex value can be set to 0 or -1. The default is 0, which means that the component is focusable and participates in sequential keyboard navigation. -1 means that the component is focusable but does not participate in keyboard navigation.
Integer
title
Displays tooltip text when the mouse moves over the element.
String
tooltip
Text to display when the user mouses over or focuses on the button. The tooltip is auto-positioned relative to the button and screen space.
String
value
The value for the button element. This value is optional and can be used when submitting a form.
String
variant
The variant changes the look of the button. Accepted variants include bare, container, border, border-filled, bare-inverse, and border-inverse. This value defaults to border.
String
border
visible
If true, the menu items are displayed. This value defaults to false.