Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline
A lightning-menu-item is a menu item within the lightning-button-menu
dropdown component. It can hold state such as checked or unchecked, and can
contain icons.
Use the class attribute to customize the styling.
When applying Lightning Design System classes or icons, check that they’re
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 resources become available only when the new release is available
in your org.
Use lightning-menu-item within lightning-button-menu, which implements the menus blueprint in the Salesforce Lightning Design System (SLDS).
The menus adapt to SLDS 1 or SLDS 2 styling based on the org’s theme or the container app that you use.
To implement a multi-select menu, use the checked attribute. The following
JavaScript example handles selection via the onselect event on
the lightning-button-menu component. Selecting a menu item applies the
selected state to that item.
Use the icon-name attribute to add an icon after the text of the menu item.
Use the prefix-icon-name attribute to add an icon before the text of the menu
item.
This example displays an icon in grayscale before the menu item text.
The SLDS action and object icons (standard and custom) have background colors. However, when you use these icons in menu items, the colors aren’t shown by default.
To specify icons with a background color in menu items, use the icon-type attribute. The icon-type attribute accepts two values.
standard (default): Sets the icon on the menu item in grayscale.
color: Sets the icon on the menu item with a background color. Action icons and object icons display a white glyph on a colored background that’s defined in SLDS. Doctype and utility icons don’t display with a background color.
To enable colored icons and backgrounds, use the icon-type="color" attribute. In this example, the standard:event icon specifies a background color and the utility:settings icon is in grayscale.
Setting icon-type="color" assigns the menu items with icons using their full color schemes, including any associated background colors. Remember that the appearance of icons can still be subject to the overall theme and styling of your Salesforce org or Lightning application.
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.
If you don’t provide a target, the link opens in the same frame or browser tab where it was clicked, which is the browser’s default behavior.
To open the link in a new browser tab, set target="_blank".
Use the is-draft and draft-alternative-text 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 is-draft is true. The
draft-alternative-text attribute is required to provide text describing the
reason the item is considered in a draft state. The draft state can be used
to show that there’s’ unsaved state or data that could be lost, for example if
there’s a user change in a customizable menu.
Attributes
Name
Description
Type
Default
Required
access-key
The keyboard shortcut for the menu item.
string
checked
If present, a check mark displays on the left of the menu item if it's selected.
boolean
false
disabled
If present, the menu item is disabled and users cannot interact with it.
boolean
false
download
The name of a file that's downloaded when clicking a link in the menu item. Used with the href attribute.
string
draft-alternative-text
Describes the reason for showing the draft indicator. This is required when is-draft is present on the lightning-menu-item tag.
string
href
URL for a link to use for the menu item.
string
icon-name
The name of an icon to display after the text of the menu item.
string
icon-type
The iconType changes the appearance of the icons in the menu item. Accepted variants include standard and color. This value defaults to standard.
string
standard
is-draft
If present, a draft indicator is shown on the menu item. A draft indicator is denoted by blue asterisk on the left of the menu item. When you use a draft indicator, include alternative text for accessibility using draft-alternative-text.
boolean
false
label
Text of the menu item.
string
prefix-icon-name
The name of an icon to display before the text of the menu item.
string
tab-index
Reserved for internal use. Use tabindex instead to indicate if an element should be focusable. tabindex can be set to 0 or -1. The default tabindex value is 0, which means that the menu item is focusable and participates in sequential keyboard navigation. The value -1 means that the menu item is focusable but does not participate in keyboard navigation.
number
target
Determines how a link in the href attribute is opened. Valid values include '_self' and '_blank'. The default is '_self', which opens the link in the current browser tab. '_blank' opens the link in a new browser tab.
string
value
A value associated with the menu item.
string
Methods
Name
Description
Argument Name
Argument Type
Argument Description
click
Clicks the anchor.
focus
Sets focus on the anchor element in the menu item.