MDUIDocs
Copy llms.txt linkCopy llms-full.txt linkView this page in MarkdownDiscuss this page with ChatGPTDiscuss full project docs with ChatGPT
Preset Colors
Custom Color
Extract from Wallpaper
Please select a wallpaper
Getting Started
AI-Assisted Development
Styles
Integration with Frameworks
Components
Avatar Badge BottomAppBar Button ButtonIcon Card Checkbox Chip CircularProgress Collapse Dialog Divider Dropdown Fab Icon Layout LinearProgress List Menu NavigationBar NavigationDrawer NavigationRail Radio RangeSlider Select SegmentedButton Slider Snackbar Switch Tabs TextField Tooltip TopAppBar
Functions
Libraries

Menu

Menus present a list of choices in a temporary surface. They appear when users interact with a button, action, or other control.

For dropdown menus, use the <mdui-dropdown> component.

Usage

Import the component:

import 'mdui/components/menu.js';
import 'mdui/components/menu-item.js';

Import the TypeScript type:

import type { Menu } from 'mdui/components/menu.js';
import type { MenuItem } from 'mdui/components/menu-item.js';

Example:

Item 1 Item 2
<mdui-menu>
  <mdui-menu-item>Item 1</mdui-menu-item>
  <mdui-menu-item>Item 2</mdui-menu-item>
</mdui-menu>

Examples

Dropdown Menu

To create a dropdown menu, use the <mdui-dropdown> component.

Dense Style

For a dense menu style, add the dense attribute to <mdui-menu>.

Disabled Items

To disable menu items, add the disabled attribute to <mdui-menu-item>.

Single Selection

For single selection, set the selects attribute to single on <mdui-menu>. The value of <mdui-menu> is the value of the selected <mdui-menu-item>.

Multiple Selection

For multiple selection, set the selects attribute to multiple on <mdui-menu>. The value of <mdui-menu> is an array of the selected <mdui-menu-item> values.

Note: For multiple selection, the value of <mdui-menu> is an array and can only be accessed and updated in JavaScript.

Icons

To add Material Icons on the left and right, add icon, end-icon attributes to <mdui-menu-item>. Use end-text attribute to add text on the right side. Alternatively, use icon, end-icon, end-text slots for the same purpose.

Setting the icon attribute to an empty string reserves space for a left-side icon so the item aligns with the others.

For single or multiple selection, use the selected-icon attribute or slot to define the selected-state icon.

To turn the menu item into a link, use the href attribute on the <mdui-menu-item> component. download, target, and rel attributes are available for link-related functionality.

Submenu

Use the submenu slot in <mdui-menu-item> to define submenu items.

Use the submenu-trigger attribute on <mdui-menu> to define how the submenu opens.

When submenu-trigger="hover" is set, use submenu-open-delay and submenu-close-delay attributes on <mdui-menu> to set the delay for opening and closing the submenu.

Custom Content

To fully customize the menu item content, use the custom slot in <mdui-menu-item>.

AttributePropertyReflectTypeDefault

The value of the menu item.

Disables the menu item.

Specifies the Material Icons name for the left icon. Alternatively, use slot="icon". An empty string reserves space for an icon.

Specifies the Material Icons name for the right icon. Alternatively, use slot="end-icon".

Specifies the right text. Alternatively, use slot="end-text".

Specifies the Material Icons name for the selected state. Alternatively, use slot="selected-icon".

Opens the submenu.

The URL for the link. When set, the component renders as an <a> element and supports link-related attributes.

Downloads the linked URL.

Note: Only available when href is specified.

Controls where the linked URL opens. Possible values:

  • _blank: Opens in a new tab or window.
  • _parent: Opens in the parent browsing context, or _self if there is no parent.
  • _self: Opens in the current browsing context (default).
  • _top: Opens in the topmost browsing context, or _self if there are no ancestors.

Note: Only available when href is specified.

Specifies the relationship of the linked URL as space-separated link types. Possible values:

  • alternate: An alternate version of the current document.
  • author: The author of the current document or article.
  • bookmark: The permalink for the nearest ancestor section.
  • external: The referenced document is not part of the same site as the current document.
  • help: A link to context-sensitive help.
  • license: Content covered by the copyright license described by the referenced document.
  • me: Links to content owned by the current document's author.
  • next: The next document in the series.
  • nofollow: Not endorsed by the original author or publisher.
  • noreferrer: Prevents the Referer header from being sent. Same effect as noopener.
  • opener: Creates a new browsing context when the hyperlink would otherwise open in a top-level context that is not auxiliary (for example, when target="_blank" is specified).
  • prev: The previous document in the series.
  • search: Links to a resource that can be used to search through the current document and its related pages.
  • tag: Marks the current document with the given tag.

Note: Only available when href is specified.

Whether the element is focused when the page loads.

The element's tab order when navigating with the Tab key.

NameParametersReturns

Simulates a mouse click on the element.

Sets focus on the element. An optional object parameter may include a preventScroll property. If preventScroll is set to true, the page will not scroll to bring the focused element into view.

Removes focus from the element.

Name

Emitted when the menu item gains focus.

Emitted when the menu item loses focus.

Emitted when the submenu starts to open. Can be prevented with event.preventDefault().

Emitted after the submenu has opened and the animations are completed.

Emitted when the submenu starts to close. Can be prevented with event.preventDefault().

Emitted after the submenu has closed and the animations are completed.

Name

Menu item text.

Left icon.

Right icon.

Right text.

Icon for the selected state.

Submenu.

Any custom content.

Name

Menu item container.

Left icon.

Text content.

Right icon.

Right text.

Icon for the selected state.

Submenu element.

AttributePropertyReflectTypeDefault

Controls whether menu items can be selected. They are not selectable by default. Possible values:

  • single: Only one item can be selected at a time.
  • multiple: Multiple items can be selected.

The value of the selected <mdui-menu-item>.

Note: The HTML attribute always accepts a string and can only be used as an initial value when selects="single". The JavaScript property is a string when selects="single" and an array of strings when selects="multiple". When selects="multiple", update the JavaScript property to change this value.

Indicates whether the menu items use a compact layout.

Defines how submenus open. Multiple space-separated values are supported. Possible values:

  • click: Opens the submenu when the menu item is clicked.
  • hover: Opens the submenu when hovering over a menu item.
  • focus: Opens the submenu when the menu item receives focus.
  • manual: Submenus can only be opened and closed programmatically; no other trigger methods can be specified.

The delay (in milliseconds) before a submenu opens on hover.

The delay (in milliseconds) before a submenu closes on hover.

NameParametersReturns

Sets focus on the element.

Removes focus from the element.

Name

Emitted when the selected state of menu items changes.

Name

Submenu items (<mdui-menu-item>), dividers (<mdui-divider>), and other elements.

Name

The corner radius of the component. You can use a specific pixel value, but it is recommended to reference design tokens.

On this page