lightning-button-menu 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.
The lightning-button-menu component supports several variants that change the look of the button. You can use a combination of the variant, icon-name, and icon-size attributes to customize the button and icon styles.
This example creates a button menu with several items during initialization. When working with an iterator, include a unique key value on lightning-menu-item. For more information, see Render Lists in the Lightning Web Components Developer Guide.
The items array definition uses the @track decorator to track mutations in the array. If the value of items changes, the component’s template rerenders.
Define items and handle the select event in your JavaScript code.
The is-loading attribute enables you to show an activity indicator while the menu is loading. You can
use this attribute, for example, to inform users that the menu is working while generating a large list of menu items.
When is-loading is true, the menu shows a spinner.
Use loading-state-alternative-text along with is-loading to specify explanatory text such as “Loading menu…” or
“Please wait while items load”.
Use the is-draft and draft-alternative-text 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 is-draft is true. Use the draft indicator with
the draft-alternative-text attribute to provide text describing the reason the menu is in a draft state.
Use the button menu’s draft state to show there’s unsaved state or unsaved data, for example, if a user changes a customizable menu.
Use a combination of the icon-name, icon-size, variant, and class attributes to customize the button and icon styles.
Icons
By default, the button shows a utility:down icon to indicate the dropdown function.
Use the icon-name attribute to place an optional utility icon
in front of the utility:down icon. Use the icon-size attribute to change the icon size from the default size of medium.
When applying SLDS classes or icons, check that they’re
available in the SLDS release tied to your org. The Lightning
Design System site shows the latest SLDS resources, which
become available only when the new release is available in your org.
Variants
Use the variant attribute with one of these values to apply styling.
border - The default variant, which shows a gray border around the button’s down arrow symbol. The area inside the border is transparent and clickable.
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 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.
Sizes
Adjust the button and icon sizes by using the size attribute with one of these values.
For bare and bare-inverse variants:
medium is the default size, which creates a 14px by 14px icon
small creates a 12px by 12px icon
x-small creates a 8px by 8px icon
large creates a 24px by 24px icon
For other variants:
medium is the default size, which creates a 32px by 32px button enclosing a 14px by 14px icon.
small creates a 24px by 24px button enclosing a 14px by 14px icon
x-small creates a 20px by 20px button enclosing a 12px by 12px icon
xx-small creates a 16px by 16px button enclosing a 8px by 8px icon
Utility Classes
To apply additional styling, use the SLDS utility classes with the class attribute.
This example adds padding around the button menu by using an SLDS class.
Component styling hooks provide CSS custom properties that use the --slds-c-* prefix and they change styling for specific elements or properties of a component. Component styling hooks are supported for SLDS 1 only. See the SLDS 1 component blueprints for available component styling hooks.
Icons aren’t available in Lightning Out, but they’re available in Lightning Components for Visualforce and other experiences.
This component’s menu items are created only if the button is
triggered. You can’t reference the menu items during initialization
or if the button isn’t triggered yet.
In Lightning Experience, a button menu that’s in an open state overlays the record edit page or modal, the global header, and the record form footer when scrolling.
You can customize the alignment of the dropdown menu relative to the button by using menu-alignment.
If you’re using lightning-button-menu in a container that specifies the overflow:hidden CSS property,
setting menu-alignment="auto" makes sure that the dropdown menu isn’t hidden from view when the menu is toggled. For mobile devices, set menu-alignment="auto" to ensure proper display of the menu.
When using this component within lightning-button-group, set variant="border-filled" on lightning-button-menu for a white button background. Otherwise, the lightning-button-menu background is transparent by default.
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 alternative-text 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 alternative-text.
lightning-button-menu 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 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.
1<lightning-button-menu2 icon-name="utility:settings"3 title="Settings"4 tooltip="Choose a settings category"5 alternative-text="Hidden text for assistive technology"6>7</lightning-button-menu>
For sighted users, make sure your descriptions for title and tooltip are not repetitive. We recommend providing detailed information to tooltip and making title more concise if you use both.
If you use the is-loading indicator, use loading-state-alternative-text to provide a description for users of assistive devices.
If you use the is-draft indicator, use draft-alternative-text to provide a description for users of assistive devices.
Custom Events
select
The event fired when the menu is selected.
The select event returns the following parameter.
Parameter
Type
Description
value
string
The value of the selected option.
The event properties are as follows.
Property
Value
Description
bubbles
false
This event does not bubble.
cancelable
true
This event can be canceled. You can call preventDefault() on this event.
composed
false
This event does not propagate outside the template in which it was dispatched.
open
The event fired when you open the dropdown menu in one of the following ways.
Tab to the button and press the Enter key
Click the button that toggles the dropdown menu
The open event doesn’t return any parameters.
The event properties are as follows.
Property
Value
Description
bubbles
false
This event does not bubble.
cancelable
false
This event has no default behavior that can be canceled. You can’t call preventDefault() on this event.
composed
false
This event does not propagate outside of the component in which it was dispatched.
close
The event fired when you close the dropdown menu in one of the following ways.
Select or unselect a dropdown menu item
Click the button that toggles the dropdown menu
Remove focus from the dropdown menu, such as by clicking outside of the dropdown menu or tabbing to another element on the page
The close event does not return any parameters.
The event properties are as follows.
Property
Value
Description
bubbles
false
This event does not bubble.
cancelable
false
This event has no default behavior that can be canceled. You cannot call preventDefault() on this event.
composed
false
This event does not propagate outside of the component in which it was dispatched.
Attributes
Name
Description
Type
Default
Required
access-key
The keyboard shortcut for the button menu.
string
alternative-text
The assistive text for the button.
string
disabled
If present, the menu can be opened by users.
boolean
false
draft-alternative-text
Describes the reason for showing the draft indicator. This is required when is-draft is true.
string
group-order
Reserved for internal use only. Describes the order of this element (first, middle or last) inside lightning-button-group.
string
icon-name
The name of the icon to be used in the format 'utility:down'. If an icon other than 'utility:down' or 'utility:chevrondown' is used, a utility:down icon is appended to the right of that icon. This value defaults to utility:down.
string
utility:down
icon-size
The size of the icon. Options include xx-small, x-small, small, medium, or large. This value defaults to medium.
string
medium
internal-datatable-actions-menu
For internal use only If this is present, then the button-menu is being used on the datatable it will remove the dropdown arrow for when 'utility:threedots' is used
boolean
false
is-draft
If present, the menu trigger shows a draft indicator.
boolean
false
is-loading
If present, the menu is in a loading state and shows a spinner.
boolean
false
label
Optional text to be shown on the button.
string
loading-state-alternative-text
Message displayed while the menu is in the loading state.
string
menu-alignment
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
nubbin
If present, a nubbin is present on the menu. A nubbin is a stub that protrudes from the menu item towards the button menu. The nubbin position is based on the menu-alignment.
boolean
false
tab-index
Reserved for internal use only. Should be set to -1 if button should not be focused when navigating with tab
number
title
Displays tooltip text when the mouse moves over the button menu.
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.