Component Blueprints

Menus

A Menu offers a list of actions or functions that a user can access.

About Menu#

The unordered menu list <ul> with role="menu" should be contained in a <div> with the class .slds-dropdown.

The target HTML element and dropdown need to be wrapped in the class .slds-dropdown-trigger dropdown-trigger_click.

Accessibility#

Markup#

  • The menu trigger is a focusable element (<a> or <button>) with aria-haspopup="true"
  • The menu trigger has the aria-expanded attribute applied and the value is set to "true" or "false" depending on if the menu is open or not.
  • The menu has role="menu" and an aria-label attribute whose value is the name of the menu trigger
  • The menu items have role="menuitem", role="menuitemcheckbox", or role="menuitemradio", depending on the selection options

Keyboard Interactions#

The main thing that distinguishes menus from other popover blocks is keyboard navigation: elsewhere, users press the Tab key to navigate through actionable items, but in a menu, users press the arrow keys to navigate.

  • Arrow keys cycle focus through menu items (including disabled menu items)
  • If a menu item opens a submenu, pressing Enter or the right arrow key opens the submenu and focus goes to the first item in the submenu
  • If a submenu is open, pressing the left arrow key closes the submenu and puts focus back on the menu item that opened the submenu
  • Tab key closes the menu and moves focus to the next focusable element on the page
  • Esc key closes the menu and moves focus back to the menu trigger
  • Any character key moves focus to the next menu item that starts with that character, if applicable

Base#

<div class="slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open">
  <button class="slds-button slds-button_icon slds-button_icon-border-filled" aria-haspopup="true" aria-expanded="true" title="Show More">
    <svg class="slds-button__icon" aria-hidden="true">
      <use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#down"></use>

With Subheaders#

Accessible Role

A subheading must have role="presentation" on the <li> and the content inside the <li> should be in a <span>.

<li class="slds-dropdown__header slds-truncate" title="Menu Sub Heading" role="separator">
  <span>Menu Sub Heading</span>
</li>
<div class="slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open">
  <button class="slds-button slds-button_icon slds-button_icon-border-filled" aria-haspopup="true" aria-expanded="true" title="Show More">
    <svg class="slds-button__icon" aria-hidden="true">
      <use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#down"></use>

With Icons#

Icons can be included on either the left, right, or both sides of an option.

Accessibility Note

If using one of the icons to indicate selection (e.g. checkmarks), be sure to check out the Menus with Selectable Items docs for the Accessibility implications.

Icon on the Left#

<div class="slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open">
  <button class="slds-button slds-button_icon slds-button_icon-border-filled" aria-haspopup="true" aria-expanded="true" title="Show More">
    <svg class="slds-button__icon" aria-hidden="true">
      <use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#down"></use>

Icon on the Right#

<div class="slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open">
  <button class="slds-button slds-button_icon slds-button_icon-border-filled" aria-haspopup="true" aria-expanded="true" title="Show More">
    <svg class="slds-button__icon" aria-hidden="true">
      <use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#down"></use>

Double Icon#

Accessibility Note

If using one of the icons to indicate selection (e.g. checkmarks), be sure to check out the Menus with Selectable Items docs.

<div class="slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open">
  <button class="slds-button slds-button_icon slds-button_icon-border-filled" aria-haspopup="true" aria-expanded="true" title="Show More">
    <svg class="slds-button__icon" aria-hidden="true">
      <use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#down"></use>

With Selectable Items#

When creating a menu with selectable items:

  • All selectable items need the proper role, either role="menuitemcheckbox" or role="menuitemradio"
  • All selectable items should contain an icon
  • Each icon must have the class slds-icon_selected on the <svg>
    • This hides icons of non-selected items
  • Items that have been selected need aria-checked="true" on the <a> element

Revealing Icons for Selected Items

A selected item reveals its icon when the class slds-is-selected is applied to the <li> and aria-checked="true" is applied to its menuitemcheckbox or menuitemradio child.

<li class="slds-dropdown__item slds-is-selected" role="presentation">
  <a role="menuitemcheckbox" aria-checked="true">...</a>
</li>
<div class="slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open">
  <button class="slds-button slds-button_icon slds-button_icon-border-filled" aria-haspopup="true" aria-expanded="true" title="Show More">
    <svg class="slds-button__icon" aria-hidden="true">
      <use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#down"></use>

With Status Notifications#

<div class="slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open">
  <button class="slds-button slds-button_icon slds-button_icon-border-filled" aria-haspopup="true" aria-expanded="true" title="Show More">
    <svg class="slds-button__icon" aria-hidden="true">
      <use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#down"></use>

To enable menu items to reflect status level notifications like Error, Success and Warning, place a modifier class onto the menuitem that has the offending notification.

The class is based on the slds-has-${level} pattern, where ${level} corresponds to the level you wish to set.

  • slds-has-error
  • slds-has-success
  • slds-has-warning
<a class="slds-has-warning" href="#" role="menuitem" tabindex="-1">...</a>

Warning Icon

For warning level menu items it is required that you switch the icon to use the currentColor variant for icons.

With Overflow Scrolling#

<div class="slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open">
  <button class="slds-button slds-button_icon slds-button_icon-border-filled" aria-haspopup="true" aria-expanded="true" title="Show More">
    <svg class="slds-button__icon" aria-hidden="true">
      <use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#down"></use>

To force overflow scrolling after either 5, 7, or 10 items, add the modifier slds-dropdown_length-* to the <div> with class slds-dropdown where the * is either 5, 7, or 10.

<div class="slds-dropdown slds-dropdown_length-5">...</div>

Scrolling for Menu Items with Icons#

To force overflow scrolling after either 5, 7, or 10 items with icons, add the modifier slds-dropdown_length-with-icon-* to the <div> with class slds-dropdown where the * is either 5, 7, or 10.

<div class="slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open">
  <button class="slds-button slds-button_icon slds-button_icon-border-filled" aria-haspopup="true" aria-expanded="true" title="Show More">
    <svg class="slds-button__icon" aria-hidden="true">
      <use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#down"></use>

With a Submenu#

To create a menu with a submenu, add the slds-has-submenu class to the list item, <li>, that will open the submenu.

Accessibility Note

Any menu item that opens a submenu must have aria-haspop="true" on the <a> within the <li>. In order to open the submenu, set aria-expanded to true on that <a> when the user clicks or hovers over the list item, or presses enter while focused on the list item. Additionally, the submenu should have role="menu" and an aria-label attribute whose value matches the name of the <li> that opened the submenu.

<li class="slds-dropdown__item slds-has-submenu" role="presentation">
  <a role="menuitem" href="#" aria-haspopup="true" aria-expanded="true" tabindex="-1">...</a>
  <div class="slds-dropdown slds-dropdown_submenu slds-dropdown_submenu-left">
    <ul class="slds-dropdown__list" role="menu" aria-label="Name of Item that Opened this Menu">...</ul>
  </div>
</li>

To open the submenu to the right of the main menu, add slds-dropdown_submenu-right to the <div> with the slds-dropdown_submenu class.

<div class="slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open">
  <button class="slds-button slds-button_icon slds-button_icon-border-filled" aria-haspopup="true" aria-expanded="true" title="Show More">
    <svg class="slds-button__icon" aria-hidden="true">
      <use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#down"></use>

To open the submenu to the left, add slds-dropdown_submenu-left to the <div> with the slds-dropdown_submenu class.

<div class="slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open">
  <button class="slds-button slds-button_icon slds-button_icon-border-filled" aria-haspopup="true" aria-expanded="true" title="Show More">
    <svg class="slds-button__icon" aria-hidden="true">
      <use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#down"></use>

Overflow Menu with Actions#

For an overflow of action items, use the overflow menu with actions styling by adding the modifier slds-dropdown_actions to the div with class slds-dropdown. This pattern is typically used in conjunction with a button group.

<div class="slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open">
  <button class="slds-button slds-button_icon slds-button_icon-x-small slds-button_icon-border-filled" aria-haspopup="true" aria-expanded="true" title="Show More">
    <svg class="slds-button__icon" aria-hidden="true">
      <use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#down"></use>

Positioning#

There are 3 options for the positioning of the menu dropdown -- left, right, and bottom. To access these options, add a modifier to the <div> with class name slds-dropdown. For the standard positioning where the dropdown aligns with the left side of the dropdown trigger, use slds-dropdown_left, as seen above.

<div class="slds-dropdown slds-dropdown_left">...</div>

Positioned Right#

To position the dropdown to align with the right of the dropdown trigger, use slds-dropdown_right.

<div class="slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open">
  <button class="slds-button slds-button_icon slds-button_icon-border-filled" aria-haspopup="true" aria-expanded="true" title="Show More">
    <svg class="slds-button__icon" aria-hidden="true">
      <use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#down"></use>

Positioned Bottom#

To position the dropdown to sit on top of the dropdown trigger, use slds-dropdown_bottom.

<div class="slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open">
  <button class="slds-button slds-button_icon slds-button_icon-border-filled" aria-haspopup="true" aria-expanded="true" title="Show More">
    <svg class="slds-button__icon" aria-hidden="true">
      <use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#down"></use>

Width#

To adjust the width of the menu dropdown add modifier slds-dropdown_* to the <div> with class slds-dropdown where the * is xx-small, x-small, small, medium, or large.

<div class="slds-dropdown slds-dropdown_left slds-dropdown_medium">...</div>
ModifierExample
.slds-dropdown_xx-small
6rem / 96px
.slds-dropdown_x-small
12rem / 192px
.slds-dropdown_small
15rem / 240px
.slds-dropdown_medium
20rem / 320px
.slds-dropdown_large
25rem / 400px

Height#

To adjust the length of visible menu dropdown items before overflow scrolling activates, add modifier slds-dropdown_length-*, or when using icons, slds-dropdown_length-with-icon-*, where the * is 5, 7, 10. Apply the height classes to both the <div>s with class slds-dropdown and slds-dropdown__list

<div class="slds-dropdown slds-dropdown_left slds-dropdown_length-7">
  <ul class="slds-dropdown__list slds-dropdown_length-7">...</ul>
</div>
ModifierExample
.slds-dropdown_length-5
5 items
.slds-dropdown_length-7
7 items
.slds-dropdown_length-10
10 items
.slds-dropdown_length-with-icon-5
5 items
.slds-dropdown_length-with-icon-7
7 items
.slds-dropdown_length-with-icon-10
10 items

Overview of CSS Classes#

Selector.slds-dropdown-trigger
Summary

Initializes a trigger element around the dropdown

Supportdev-ready
Restrictdiv, span, li
VariantTrue
Selector.slds-dropdown-trigger_hover
Summary

If someone is using javascript for click to toggle - this modifier will help

Restrict.slds-dropdown-trigger
Selector.slds-dropdown-trigger_click
Summary

If someone is using javascript for click to toggle - this modifier will help

Restrict.slds-dropdown-trigger
Selector.slds-is-open
Summary

Opens dropdown menu when invoked on click

Restrict.slds-dropdown-trigger_click
ModifierTrue
Selector.slds-dropdown
Summary

Initializes dropdown

Restrict.slds-dropdown-trigger div, .slds-dropdown-trigger ul, .slds-docked-composer_overflow div
Selector.slds-listbox
Summary

Listbox container

Supportdev-ready
Restrict.slds-dropdown ul, .slds-dueling-list__options ul, .slds-pill_container ul, .slds-listbox_selection-group ul, .slds-combobox_container ul, .slds-form-element__control ul, .slds-popover__body ul
VariantTrue
Selector.slds-listbox_inline
Summary

Inline listbox

Restrict.slds-listbox
ModifierTrue
Selector.slds-listbox_horizontal
Summary

Horizontal listbox

Restrict.slds-listbox
ModifierTrue
Selector.slds-listbox__item
Summary

Listbox item

Restrict.slds-listbox > li
Selector.slds-listbox__option
Summary

Choosable option within listbox

Restrict.slds-listbox__item > div
Selector.slds-listbox__option-header
Summary

Header for choosable option within listbox

Restrict.slds-listbox__option h3
Selector.slds-listbox__option-icon
Summary

Container for listbox option icon

Restrict.slds-listbox__option span
Selector.slds-has-focus
Summary

Focus state of a vertical listbox option

Restrict.slds-listbox__option
ModifierTrue
Selector.slds-listbox__option_entity
Summary

Modifies the listbox option if it contains an entity object

Restrict.slds-listbox__option
Selector.slds-listbox__option_plain
Summary

Modifies the listbox option if it contains an plain object or string

Restrict.slds-listbox__option
Selector.slds-listbox__option_has-meta
Summary

If the listbox option has metadata or secondary information that sits below its primary text

Restrict.slds-listbox__option
Selector.slds-is-selected
Summary

Modifier that makes selected icon visible

Restrict.slds-listbox__option
ModifierTrue
Selector.slds-listbox__option-text_entity
Summary

The main text of an entity listbox

Restrict.slds-listbox__option span
Selector.slds-listbox__option-meta
Summary

The metadata or secondary text of an entity listbox

Restrict.slds-listbox__option span
Selector.slds-listbox__icon-selected
Summary

The icon within a plain listbox that indicates if an option has been selected or not.

Restrict.slds-listbox__item svg
Selector.slds-listbox_vertical
Summary

Creates a vertical listbox

Restrict.slds-listbox
ModifierTrue
Selector.slds-dropdown_length-5
Summary

Forces overflow scrolling after 5 list items

Restrict.slds-dropdown, .slds-dropdown__list, .slds-listbox
ModifierTrue
Selector.slds-dropdown_length-7
Summary

Forces overflow scrolling after 7 list items

Restrict.slds-dropdown, .slds-dropdown__list, .slds-listbox
ModifierTrue
Selector.slds-dropdown_length-10
Summary

Forces overflow scrolling after 10 list items

Restrict.slds-dropdown, .slds-dropdown__list, .slds-listbox
ModifierTrue
Selector.slds-dropdown_length-with-icon-5
Summary

Forces overflow scrolling after 5 list items with an icon

Restrict.slds-dropdown, .slds-dropdown__list, .slds-listbox
ModifierTrue
Selector.slds-dropdown_length-with-icon-7
Summary

Forces overflow scrolling after 7 list items with an icon

Restrict.slds-dropdown, .slds-dropdown__list, .slds-listbox
ModifierTrue
Selector.slds-dropdown_length-with-icon-10
Summary

Forces overflow scrolling after 10 list items with an icon

Restrict.slds-dropdown, .slds-dropdown__list, .slds-listbox
ModifierTrue
Selector.slds-dropdown_inverse
Summary

Theme

Restrict.slds-dropdown
ModifierTrue
Selector.slds-dropdown__header
Summary

Adds padding to area above dropdown menu list

Restrict.slds-dropdown li
Selector.slds-dropdown__item
Summary

Initializes dropdown item

Restrict.slds-dropdown li
Selector.slds-is-unsaved
Summary

Dirty state for a nav item

Restrict.slds-context-bar__item, .slds-dropdown__item
Selector.slds-has-error
Summary

Places a menu item into an errored state

Restrict.slds-dropdown__item > a
ModifierTrue
Selector.slds-has-success
Summary

Places a menu item into a success state

Restrict.slds-dropdown__item > a
ModifierTrue
Selector.slds-has-warning
Summary

Places a menu item into a warning state

Restrict.slds-dropdown__item > a
ModifierTrue
Selector.slds-icon_selected
Summary

If menu contains menuitemcheckbox then this toggles the selected icon when it is selected

Restrict.slds-dropdown__item svg
Selector.slds-is-selected
Summary

If menu contains menuitemcheckbox then this handles the selected states

Restrict.slds-dropdown__item
ModifierTrue
Selector.slds-has-submenu
Summary

true

Restrict.slds-dropdown__item
Selector.slds-dropdown_submenu
Summary

true

Restrict.slds-has-submenu div
Selector.slds-dropdown_submenu-left
Summary

Open submenu to the left of the parent menu item

Restrict.slds-dropdown_submenu
ModifierTrue
Selector.slds-dropdown_submenu-right
Summary

Open submenu to the right of the parent menu item

Restrict.slds-dropdown_submenu
ModifierTrue
Selector.slds-dropdown_submenu-bottom
Summary

Open submenu along the bottom of the parent menu item

Restrict.slds-dropdown_submenu
Selector.slds-has-notification
Summary

Creates styles for a Tab Item when its tab has new activity in

Restrict.slds-tabs_default__item, .slds-dropdown__item
Selector.slds-indicator_unread
Summary

Unread notification icon

Restrict.slds-has-notification span
Selector.slds-dropdown_left
Summary

Positions dropdown to left side of target

Restrict.slds-dropdown
ModifierTrue
Selector.slds-dropdown_right
Summary

Positions dropdown to right side of target

Restrict.slds-dropdown
ModifierTrue
Selector.slds-dropdown_bottom
Summary

Positions dropdown to above target

Restrict.slds-dropdown
ModifierTrue
Selector.slds-dropdown_xx-small
Summary

Sets min-width of 6rem/96px

Restrict.slds-dropdown
ModifierTrue
Selector.slds-dropdown_x-small
Summary

Sets min-width of 12rem/192px

Restrict.slds-dropdown
ModifierTrue
Selector.slds-dropdown_small
Summary

Sets min-width of 15rem/240px

Restrict.slds-dropdown
ModifierTrue
Selector.slds-dropdown_medium
Summary

Sets min-width of 20rem/320px

Restrict.slds-dropdown
ModifierTrue
Selector.slds-dropdown_large
Summary

Sets min-width of 25rem/400px

Restrict.slds-dropdown
ModifierTrue
Selector.slds-dropdown_fluid
Summary

Sets width equal to input

Restrict.slds-dropdown
ModifierTrue
Selector.slds-dropdown_length-5
Summary

Forces overflow scrolling after 5 list items

Restrict.slds-dropdown, .slds-dropdown__list, .slds-listbox
ModifierTrue
Selector.slds-dropdown_length-7
Summary

Forces overflow scrolling after 7 list items

Restrict.slds-dropdown, .slds-dropdown__list, .slds-listbox
ModifierTrue
Selector.slds-dropdown_length-10
Summary

Forces overflow scrolling after 10 list items

Restrict.slds-dropdown, .slds-dropdown__list, .slds-listbox
ModifierTrue
Selector.slds-dropdown_length-with-icon-5
Summary

Forces overflow scrolling after 5 list items with an icon

Restrict.slds-dropdown, .slds-dropdown__list, .slds-listbox
ModifierTrue
Selector.slds-dropdown_length-with-icon-7
Summary

Forces overflow scrolling after 7 list items with an icon

Restrict.slds-dropdown, .slds-dropdown__list, .slds-listbox
ModifierTrue
Selector.slds-dropdown_length-with-icon-10
Summary

Forces overflow scrolling after 10 list items with an icon

Restrict.slds-dropdown, .slds-dropdown__list, .slds-listbox
ModifierTrue
Selector.slds-nubbin_top
Summary
Restrict.slds-popover, .slds-dropdown
ModifierTrue
Selector.slds-nubbin_top-left
Summary
Restrict.slds-popover, .slds-dropdown
ModifierTrue
Selector.slds-nubbin_top-right
Summary
Restrict.slds-popover, .slds-dropdown
ModifierTrue
Selector.slds-nubbin_bottom
Summary
Restrict.slds-popover, .slds-dropdown
ModifierTrue
Selector.slds-nubbin_bottom-left
Summary
Restrict.slds-popover, .slds-dropdown
ModifierTrue
Selector.slds-nubbin_bottom-right
Summary
Restrict.slds-popover, .slds-dropdown
ModifierTrue
Selector.slds-nubbin_left
Summary
Restrict.slds-popover, .slds-dropdown
ModifierTrue
Selector.slds-nubbin_left-top
Summary
Restrict.slds-popover, .slds-dropdown
ModifierTrue
Selector.slds-nubbin_left-bottom
Summary
Restrict.slds-popover, .slds-dropdown
ModifierTrue
Selector.slds-nubbin_right
Summary
Restrict.slds-popover, .slds-dropdown
ModifierTrue
Selector.slds-nubbin_right-top
Summary
Restrict.slds-popover, .slds-dropdown
ModifierTrue
Selector.slds-nubbin_right-bottom
Summary
Restrict.slds-popover, .slds-dropdown
ModifierTrue
Selector.slds-nubbin_top-left-corner
Summary
Restrict.slds-popover, .slds-dropdown
ModifierTrue
Selector.slds-nubbin_bottom-left-corner
Summary
Restrict.slds-popover, .slds-dropdown
ModifierTrue
Selector.slds-nubbin_top-right-corner
Summary
Restrict.slds-popover, .slds-dropdown
ModifierTrue
Selector.slds-nubbin_bottom-right-corner
Summary
Restrict.slds-popover, .slds-dropdown
ModifierTrue
Selector.slds-nubbin_left-top-corner
Summary
Restrict.slds-popover, .slds-dropdown
ModifierTrue
Selector.slds-nubbin_right-top-corner
Summary
Restrict.slds-popover, .slds-dropdown
ModifierTrue
Selector.slds-nubbin_left-bottom-corner
Summary
Restrict.slds-popover, .slds-dropdown
ModifierTrue
Selector.slds-nubbin_right-bottom-corner
Summary
Restrict.slds-popover, .slds-dropdown
ModifierTrue

Menus Release Notes

2.23.0

Changed

  • Updated Dropdown Inverse item disabled color

2.21.0

Fixed

  • Fixed invalid aria roles issue in subheadings with role=presentation

2.15.1

Added

  • Added aria-expanded attribute to menu triggers with value dependent on menu's open state

2.14.0

Changed

  • Added default text color to dropdown menus to fix issue with dropdowns inheriting font color from parent blueprints

2.13.1

Changed

  • Removed Mobile examples as they did not conform to the specification.

2.11.7

Added

  • Added documentation and examples for mobile/touch context

2.10.0

Changed

  • For touch devices:
    • Set tap target size of menu row item to $height-tappable (2.75rem)
    • Remove padding from .slds-dropdown after increased tap target size of menu row items
    • Set font-size of menu to $font-size-5 (1rem)
  • Remove font-size declaration from slds-dropdown__header to inherit font-size from body element
  • Update .slds-dropdown_fluid to have a min-width set to $size-x-small (12rem) to prevent menus from being unreadable when associated with inputs that have a small width

Added

  • Added explicit right: auto to slds-dropdown_left

2.8.0

Added

  • 3 levels of status for menu items to alert the user - error, success, and warning

Changed

  • Increased font size to 14px applied bold font weight in slds-dropdown__header.

Removed

  • Removed slds-text-title_caps from menu sub headers.