Button Menu

lightning:buttonMenu

Represents a dropdown menu with a list of actions or functions.

For Aura components only. For LWC development, use lightning-button-menu.

For Use In

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.

1<lightning:buttonMenu
2  iconName="utility:settings"
3  iconSize="small"
4  variant="border-filled"
5  alternativeText="Settings"
6  onselect="{! c.handleMenuSelect }"
7>
8  <lightning:menuItem label="Font" value="font" />
9  <lightning:menuItem label="Size" value="size" />
10  <lightning:menuItem label="Format" value="format" />
11</lightning:buttonMenu>

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.

Use the lightning:menuSubheader component to create subheadings in the list of menu items.

Generate Menu Items with aura:iteration 

This example creates a button menu with several items during initialization.

1<aura:component>
2  <aura:handler name="init" value="{!this}" action="{!c.createItems}" />
3  <lightning:buttonMenu
4    alternativeText="Action"
5    onselect="{! c.handleMenuSelect }"
6  >
7    <aura:iteration var="action" items="{! v.actions }">
8      <lightning:menuItem
9        aura:id="actionMenuItems"
10        label="{! action.label }"
11        value="{! action.value }"
12      />
13    </aura:iteration>
14  </lightning:buttonMenu>
15</aura:component>

The client-side controller creates the array of menu items and set its value on the actions attribute.

1({
2  createItems: function (cmp, event) {
3    var items = [
4      { label: "New", value: "new" },
5      { label: "Edit", value: "edit" },
6      { label: "Delete", value: "delete" },
7    ];
8    cmp.set("v.actions", items);
9  },
10});

Show the Loading State of a Menu 

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.

For more information, see the WAI-ARIA Specification.

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 

NameDescriptionTypeDefaultRequired
accesskeySpecifies a shortcut key to activate or focus an element.String
alternativeTextThe assistive text for the button.String
bodyThe body of the component.Aura.ComponentDefRef[]
classA CSS class for the outer element, in addition to the component's base classes.String
disabledIf true, the menu is disabled. Disabling the menu prevents users from opening it. This value defaults to false.Booleanfalse
draftAlternativeTextDescribes the reason for showing the draft indicator. This is required when the isDraft attribute is true.String
iconNameThe 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.Stringutility:down
iconSizeThe size of the icon. Options include xx-small, x-small, small, medium, or large. This value defaults to medium.Stringmedium
isDraftIf true, the menu trigger shows a draft indicator. This value defaults to false.Booleanfalse
isLoadingIf true, the menu is in a loading state and shows a spinner. This value defaults to false.Booleanfalse
labelOptional text to be shown on the button.String
loadingStateAlternativeTextMessage displayed while the menu is in the loading state.String
menuAlignmentDetermines 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.Stringleft
nameThe name for the button element. This value is optional and can be used to identify the button in a callback.String
onblurThe action triggered when the element releases focus.Aura.Action
onfocusThe action triggered when the element receives focus.Aura.Action
onopenAction fired when the menu is opened.Aura.Action
onselectAction fired when a menu item is selected. The 'detail.menuItem' property of the passed event is the selected menu item.Aura.Action
tabindexSpecifies 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
titleDisplays tooltip text when the mouse moves over the element.String
tooltipText 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
valueThe value for the button element. This value is optional and can be used when submitting a form.String
variantThe 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.Stringborder
visibleIf true, the menu items are displayed. This value defaults to false.Booleanfalse

Methods 

NameDescriptionArgument NameArgument TypeArgument Description
focusSets focus on the element.