Mushilu-San UI

Search components

PlaygroundStorybookGitHub
Overlays

Dropdown menu

A button that opens a menu of actions for the item or page around it.

Selector: mui-dropdown-menu

Import
import { DropdownMenu, DropdownTrigger, DropdownItem, DropdownSeparator } from '@mushilu-san/ui/overlays';
PreviewCode

Loading example…

Overview

Dropdown menu wraps a muiDropdownTrigger button and a list of mui-dropdown-item actions. open is a two-way model. Items are role="menuitem", and color="danger" marks a destructive action.

Arrow keys, Home and End move between enabled items. Escape closes the menu and returns focus to the trigger. Tab closes it. Choosing an item closes the menu unless closeOnSelect is off.

When to use

  • A set of actions for one item, such as Edit, Duplicate and Delete for a row.
  • A toolbar overflow with secondary commands.

When not to use

  • Choosing a value that sets a field. Use a select. Use Select instead.
  • Site navigation with pages. Use a navigation menu. Use Navigation menu instead.

Guidelines

Do

  • Keep actions as verbs, such as "Duplicate".
  • Put destructive actions last, separated and in the danger colour.

Don't

  • Do not nest menus inside menus.
  • Do not use a menu for a single action. Use a button.

Accessibility

Roles and attributes

ElementRoleNotes
triggerbuttonaria-expanded follows the menu state.
menu itemmenuitemaria-disabled when disabled.
separatorseparator

Keyboard

KeysAction
EnterSpaceArrowDownOpens the menu on the trigger.
ArrowDownArrowUpMove between enabled items (roving focus).
HomeEndMove to the first or last enabled item.
EscapeCloses the menu and returns focus to the trigger.
TabCloses the menu.
  • Disabled items are skipped by the arrow keys.

API

DropdownMenu

Selector: mui-dropdown-menu

NameTypeDefaultDescription
closeOnEscapebooleantrue Closes the menu on Escape and returns focus to the trigger. Default `true`. Accepts attribute presence, e.g. <… closeOnEscape>.
closeOnSelectbooleantrue Closes the menu after an item is chosen. Default `true`. Accepts attribute presence, e.g. <… closeOnSelect>.
NameTypeDefaultDescription
openbooleanfalse Whether the menu is open. Two-way bindable with `[(open)]`.
NameTypeDescription
openedvoid Emits when the menu opens.
closedvoid Emits when the menu closes, however it was closed.

CSS parts

  • ::part(panel)
  • ::part(root)

DropdownTrigger

Selector: [muiDropdownTrigger]

CSS parts

  • ::part(trigger)

DropdownItem

Selector: mui-dropdown-item

NameTypeDefaultDescription
color'danger' | 'default''default' Colour of the item: `default` or `danger` for destructive actions. Default `default`.
disabledbooleanfalse Disables the item. It is skipped by the arrow keys. Accepts attribute presence, e.g. <… disabled>.
shortcutstring | undefined— Keyboard shortcut shown on the right, for display only.
hasIconbooleanfalse Reserves space on the left for an icon in a `slot="icon"` element. Accepts attribute presence, e.g. <… hasIcon>.
NameTypeDescription
itemClickvoid Emits when the item is chosen.

CSS parts

  • ::part(button)
  • ::part(icon)
  • ::part(item)
  • ::part(label)
  • ::part(shortcut)

DropdownSeparator

Selector: mui-dropdown-separator

CSS parts

  • ::part(separator)

Tokens

  • --mui-color-surface-raised
  • --mui-color-border
  • --mui-shadow-3
  • --mui-color-danger
  • --mui-color-focus-ring