Skip to content

MenuItem

A MenuItem is a selectable option within a Menu.

  • Item labelDescription text
NameValue
Props
highlighted
active
selected
multiselect
disabled
icon
label
boldLabel
match
supportingText
description
hideDescriptionOverflow
searchQuery
action
View
Reading direction
Note: For icon properties, the relevant icon also needs to be imported from the @wikimedia/codex-icons package. See the usage documentation for more information.

Overview

When to use MenuItem

MenuItem is an “internal” component, used exclusively to represent content within a Menu. It cannot be used by itself.

About MenuItem

MenuItems can have one of two functions:

  1. Selectable options
    MenuItems in form elements like Select or Combobox are selectable.
  2. Trigger actions
    MenuItems in MenuButton trigger actions. There are two types of actions:
    • Standard actions
      neutral actions such as "Edit" or "Share".
    • Destructive actions
      actions with potentially negative or irreversible impact, such as "Delete".

MenuItem includes the following elements.

Media (optional)

An Icon or Thumbnail can be included in order to provide more context about the menu item content.

  • Use an Icon to visually reinforce the MenuItem content.
  • Use a Thumbnail to provide a preview of the MenuItem content.

Label

A clear and descriptive title for the MenuItem.

Supporting text (optional)

Text that supports or explains the label. This is often used to indicate search redirects in a Menu of search results.

  • Keep supporting text short to avoid overcrowding the layout.
  • Include supporting text within brackets to explain where a search result is redirected from.

Search query match (optional)

In the context of a search suggestions menu, this optional text displays the alternative label of an item that matches the search query (e.g. an alias).

Description (optional)

Descriptive text that provides additional information about the menu item.

  • Keep description text concise to keep the Menu scannable and readable.

Examples

Note that these demos do not properly show some interactive states of MenuItems (like active or hovered/highlighted), since they display MenuItems as standalone or as part of an always-expanded, detached Menu. To understand the full interactivity of MenuItems, check out a component that contains a Menu, like Select, Lookup, or TypeaheadSearch.

Basic usage

By default, the MenuItem's label will be displayed in the regular font weight. This MenuItem has a bold label and a description.

If a url property is included, the MenuItem will be wrapped in an anchor tag.

With icon

With thumbnail

Search query highlight

When a MenuItem displays a search result, the current searchQuery can be provided and will be visually differentiated within the MenuItem's label. The searchQuery text will have a normal font weight, while the rest of the label will be bold, which is meant to bring attention to the available suggestions based on the current searchQuery.

In the example below, the searchQuery is "Co".

Developer notes

To highlight the search query within the label text, set highlightQuery to true and provide the current searchQuery text.

Search query match

For search results, a match property may be included that represents the text related to that item that matched the searchQuery (e.g. a Wikidata alias). The match will be displayed after the label.

In the example below, the searchQuery is "felis margarita," an alias of the Wikidata item "sand cat." The match is included when highlighting the search query within a result's title.

Supporting text

Text that supports or explains the label can be added via the supportingText prop. This text will be displayed after the label in a more subtle color, and is not included when highlighting a search query within the title.

The example below shows a result for the search term "Corn," which redirects to the article for "Maize" on English Wikipedia.

Multiple languages

The MenuItem component can support different languages for different text elements. The example below demonstrates a search result in a Greek interface for the English word "moon."

Developer notes

Individual lang attributes can be set for the label, description, match, and supportingText props via the language prop, which is an object of lang attributes for those props.

Vue usage

WARNING

This is not a standalone component, nor will it typically be directly used. It's intended for use by the Menu component, which will provide it with props and menu state information. Visit Menu for more details.

A value must be provided, and various optional elements can be displayed:

  • A human-readable label
  • A description
  • A thumbnail or icon

Alternately, the entire content and layout of the MenuItem can be customized via the default slot.

Props

Prop nameDescriptionTypeDefault
id(required)ID for HTML id attribute.string
value(required)The value provided to the parent menu component when this menu item is selected.MenuItemValue
disabledWhether the menu item is disabled.booleanfalse
selectedWhether this menu item is selected.booleanfalse
activeWhether this menu item is being pressed.booleanfalse
highlightedWhether this menu item is visually highlighted due to hover or keyboard navigation.booleanfalse
labelLabel for the menu item. If this isn't provided, the value will be displayed instead.string''
matchText that matches current search query. Only used for search results and will be displayed after the label.string''
supportingTextText that supports the label. Supporting text will appear next to the label in a more subtle color.string''
urlURL for the menu item. If provided, the content of the menu item will be wrapped in an anchor tag.string''
iconIcon for the menu item.Icon''
showThumbnailWhether a thumbnail (or a placeholder icon) should be displayed.booleanfalse
thumbnailThumbnail for the menu item.Thumbnail|nullnull
descriptionDescription of the menu item.string|null''
searchQueryThe search query to be highlighted within the menu item's title.string''
boldLabelWhether to bold menu item labels.booleanfalse
hideDescriptionOverflowWhether to hide description text overflow via an ellipsis.booleanfalse
languageOptional language codes for label, match, supporting text, and description.

If included, that language code will be added as a lang attribute to the element wrapping that text node.
MenuItemLanguageData{}
actionMenuItems inside a MenuButton can also support an "action" propButtonAction'default'
multiselectWhether this menu is in multiselect mode.booleanfalse

Events

Event namePropertiesDescription
changemenuState MenuState - State to change setState boolean - Whether to set that state to this menu itemEmitted when the menu item becomes selected, active or highlighted in response to user interaction. Handled in the Menu component.

Slots

NameDescriptionBindings
defaultCustom menu item content.