Skip to content

MenuButton

The MenuButton component is a ToggleButton that, when toggled on, displays a Menu with options.

Guidelines

When to use menu buttons

MenuButton serves for accessing additional actions or settings associated with the button that triggers the menu.

Use the MenuButton component when the space is limited and you need to provide users with a set of related actions or options within a single button.

Avoid using MenuButton when there are only one or two actions to display. In that case, consider using separate buttons instead. Additionally, refrain from using MenuButton if the actions displayed are essential and require immediate visibility without additional interaction.

Specifications

MenuButton includes the following items:

  1. ToggleButton
    A single button to display the menu. It can include an icon, a clear label, or both.
  2. Menu
    A selectable list of related actions or options that can optionally contain start icons.

Specification of MenuButton.

Component limitations

The MenuButton will display a minimum of 2 actions or options. There is no limit on the number of visible menu items; a scrollbar will appear if the menu size exceeds manageable limits.

The Menu inside the MenuButton is set to a base size of @size-1600 (equivalent to 256px in the default Codex theme). When space is constrained, this can shrink down to a minimum width of @size-800 (equivalent to 128px in the default Codex theme).

Position of the menu

When the menu is presented in LTR direction, Bottom-Right is the default position, while Bottom-Left is the default position in RTL direction. As an alternative to these base positions, the following ones can also be used to fit the space or scroll in the screen:

MenuButton positions determined by the display direction of the Menu.

  1. Bottom-Right
  2. Bottom-Left
  3. Top-Right
  4. Top-Left
  5. Right-Top
  6. Right-Bottom
  7. Left-Top
  8. Left-Bottom

Refer to the MenuButton component in Codex Figma.

Types

Since MenuButton uses a ToggleButton and a Menu, it can use any of their available properties, such as displaying text on the button or including icons in the menu.

Two MenuButtons: one with an icon-only button and menu items with text, and the other with a text button and menu items with icons and text.

Interaction states

The Menu appears once the ToggleButton is selected.

Two MenuButtons: one with an icon-only button and menu items with text, and the other with a text button and menu items with icons and text.

  1. Default
  2. Hover
  3. Active
  4. Focus
  5. Toggled-on focus
  6. Disabled

Best practices

Consider the following recommendations when working with menu buttons.

A MenuButton being used to display different actions.

Do:
  • Use MenuButton to display additional actions within a single button.

A MenuButton incorrectly used to select an option.

Don't:
  • Use the MenuButton as a selector for choosing an option. In such cases, use a Select instead.

A MenuButton displaying menu items with start icons.

Do:
  • Enhance the visual representation of text by incorporating icons into menu items.

A MenuButton displaying menu items with thumbnails.

Don't:
  • Use thumbnails within the menus of MenuButton, as they could make the menu excessively large.

A MenuButton displaying four normal actions and one destructive.

Do:
  • Use the color-destructive in case an action within the Menu is destructive.

A MenuButton displaying three normal actions and two destructive.

Don't:
  • Include more than one destructive action within the menu.

Keyboard navigation

KeyFunction
EnterIf the focus is placed on the button, it opens and closes the menu. If the focus is placed in any of the options within the displayed menu, it activates that option.
SpaceIf the focus is placed on the button, it opens and closes the menu.
Down arrow / Up arrowIf the menu is displayed, it navigates through menu options.
EscIt closes the menu when it is open.
HomeOptionally, it moves the focus to the first option. Optionally, in a single-select listbox, selection may also move with focus. Supporting this key is strongly recommended for lists with more than five options.
EndOptionally, it moves the focus to the last option. Optionally, in a single-select listbox, selection may also move with focus. Supporting this key is strongly recommended for lists with more than five options.

Demos

Configurable

NameValue
Props
disabled
Slots
default
View
Reading direction

Basic usage

MenuButton has two required props: selected and menuItems. The selected prop needs to be bound with v-model.

Customize the content within the toggle button by using the default slot. You can pass in text and/or a Icon to the slot content.

Icon-only

When using an icon-only toggle button, add an aria-label.

To add an icon, insert the Icon component in the slot content. Refer to the Icon component and the overview of icons to learn more about using icons.

With icon and text

You can add icons to individual menu items by including the icon property in the list of menuItems. Be sure to import or require each icon, then add the icon name from this list of icons as the icon property's value.

You can use the menuConfig prop to set a visible menu item limit. Refer to the MenuConfig type for more configuration options.

Triggering events on selection

It is possible for a MenuButton to trigger an immediate action when the user selects an item, instead of or in addition to storing their choice as a persistent value. In this demo, the component listens for @update:selected events from the MenuButton component, handles the selection change with the onSelect method, displays a temporary message using the Message component, and resets the selection after a few seconds.

Other features

The MenuButton component has an internal ToggleButton and Menu. You can use the following features from those components in the MenuButton component:

Vue usage

Props

Prop nameDescriptionTypeDefault
selected(required)Value of the current selection.

Must be bound with v-model:selected.
string|number|null
menuItems(required)Menu items and/or menu group definitions.

Menu groups and individual menu items will be output in the order they appear here.
(MenuButtonItemData|MenuGroupData)[]
menuConfigConfiguration for various menu features. All properties default to false.

See the MenuConfig type.
MenuConfig{}
disabledWhether the dropdown is disabled.booleanfalse
footerInteractive footer item.

This is a special menu item which is pinned to the bottom of the menu. When scrolling is enabled within the menu, the footer item will always be visible at the bottom of the menu. When scrolling is not enabled, the footer item will simply appear as the last menu item.

The footer item is selectable, like other menu items.
MenuItemDatanull

Events

Event namePropertiesDescription
update:selectedselected string|number - The new selected valueWhen the selected value changes.

Slots

NameDescriptionBindings
defaultMenuButton content
menu-itemDisplay of an individual item in the menumenu-item MenuItemData - The current menu item