Mushilu-San UI

Search components

PlaygroundStorybookGitHub
Overlays

Context menu

A menu that opens at the pointer on right-click or long press, with actions for the area under it.

Selector: mui-context-menu

Import
import { ContextMenu, ContextMenuTrigger, ContextMenuItem, ContextMenuSeparator } from '@mushilu-san/ui/overlays';
PreviewCode

Loading example…

Overview

Context menu wraps an area marked with muiContextMenuTrigger. Right-click opens the menu at the pointer. On touch screens a long press does the same. open is a two-way model, and items are mui-context-menu-item entries.

Escape closes the menu. Choosing an item closes it unless closeOnSelect is off.

When to use

  • Secondary actions on a file, row or canvas item, where the same actions also exist elsewhere.
  • Power-user shortcuts in a document or editor.

When not to use

  • The only way to reach an action. Keyboard and touch users may not find it. Use Dropdown menu instead.
  • Choosing a value. Use a select. Use Select instead.

Guidelines

Do

  • Show the same actions in a visible control too, such as a "more" button.
  • Mark destructive items with color="danger".

Don't

  • Do not rely on right-click as the only way to open a menu.

Accessibility

Roles and attributes

ElementRoleNotes
menu itemmenuitemaria-disabled when disabled.
separatorseparator

Keyboard

KeysAction
ArrowDownArrowUp, HomeEndMove between items.
EscapeCloses the menu.
  • A context menu is a supplement. Always offer the same actions through a visible control.

API

ContextMenu

Selector: mui-context-menu

NameTypeDefaultDescription
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)

ContextMenuTrigger

Selector: [muiContextMenuTrigger]

CSS parts

  • ::part(trigger)

ContextMenuItem

Selector: mui-context-menu-item

NameTypeDefaultDescription
disabledbooleanfalse Disables the item. It is skipped by the arrow keys. Accepts attribute presence, e.g. <… disabled>.
color'danger' | 'default''default' Colour of the item: `default` or `danger`. Default `default`.
shortcutstring | undefined— Keyboard shortcut shown on the right, for display only.
NameTypeDescription
selectedvoid Emits when the item is chosen.

CSS parts

  • ::part(button)
  • ::part(item)

ContextMenuSeparator

Selector: mui-context-menu-separator

CSS parts

  • ::part(separator)

Tokens

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