Menu Item

lightning:menuItem

Represents a list item in a menu.

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

For Use In

Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline

A lightning:menuItem is a menu item within the lightning:buttonMenu dropdown component. It can hold state such as checked or unchecked, and can contain icons.

Use the class attribute to customize the styling.

This component implements styling from menus in the Lightning Design System.

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.

Here is an example.

1<aura:component>
2  <lightning:buttonMenu alternativeText="Toggle menu">
3    <lightning:menuItem
4      label="Menu Item 1"
5      value="menuitem1"
6      iconName="utility:table"
7    />
8  </lightning:buttonMenu>
9</aura:component>

Multi-select Menus 

To implement a multi-select menu, use the checked attribute. The following client-side controller example handles selection via the onselect event on the lightning:buttonMenu component. Selecting a menu item applies the selected state to that item.

1({
2  handleActive: function (cmp, event) {
3    var menuItem = event.getSource();
4    // Toggle check mark on the menu item
5    menuItem.set("v.checked", !menuItem.get("v.checked"));
6  },
7});

Adding Icons to Menu Items 

Use the iconName attribute to add an icon after the text of the menu item. Use the prefixIconName attribute to add an icon before the text of the menu item. For each attribute, specify a utility icon from utility icons in Lightning Design System.

This example specifies an icon to display before the menu item text.

1<lightning:buttonMenu>
2  <lightning:menuItem prefixIconName="utility:user" label="Menu item" />
3  <lightning:menuItem label="Another menu item" />
4</lightning:buttonMenu>

Using URLs in Menu Items 

The href attribute allows you to use the button menu for navigation. This example specifies a URL in the menu item’s href attribute to create a link. The link is applied to the content of the menu item, including text and icons.

1<lightning:menuItem href="https://google.com" label="A linked menu item" />

Draft Indicators 

Use the isDraft and draftAlternativeText attributes together to indicate that the menu item is in an unsaved state. The draft indicator, an asterisk, is shown for the menu item when isDraft is true. The draftAlternativeText attribute is required to provide text describing the reason the item is considered in a draft state. The 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.

Attributes 

NameDescriptionTypeDefaultRequired
accesskeySpecifies a shortcut key to activate or focus an element.String
bodyThe body of the component. In markup, this is everything in the body of the tag.Aura.Component[]
checkedIf not specified, the menu item is not checkable. If true, a check mark is shown to the left of the menu item. If false, a check mark is not shown but there is space to accommodate one.Boolean
classA CSS class for the outer element, in addition to the component's base classes.String
disabledIf true, the menu item is not actionable and is shown as disabled.Boolean
downloadThe name of a file that's downloaded when clicking a link in the menu item. Used with the href attribute.String
draftAlternativeTextDescribes the reason for showing the draft indicator. This is required when the isDraft attribute is trueString
hrefURL for a link to use for the menu item.String
iconNameThe name of an icon to display after the text of the menu item.String
isDraftIf true, the menu item shows a draft indicator. This value defaults to false.Booleanfalse
labelText of the menu item.String
onactiveDEPRECATED. The action triggered when this menu item is selected.Aura.Action
onblurThe action triggered when the element releases focus.Aura.Action
onfocusThe action triggered when the element receives focus.Aura.Action
prefixIconNameThe name of an icon to display before the text of the menu item.String
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
valueA value associated with the menu item.String

Methods 

NameDescriptionArgument NameArgument TypeArgument Description
focusSets focus on the element.