Skip to content
IndexRequest a UIAboutContact

Context Menu

A custom menu on right-click, long-press or the Menu key, with arrow keys, Escape and edge-aware placement.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Clean UI mockup of a custom context menu opened over a file card in a file manager: a small white rounded menu with soft shadow at the pointer position listing Open, Rename, Duplicate and Share with muted keyboard shortcut hints on the right, a thin divider, then Delete in red at the bottom, the first item highlighted in light grey, the file card behind it slightly selected, light theme, flat modern style. Negative: heavy shadows, clutter, text errors, device frames. Reduced motion: static design.

About this pattern

Definition

A context menu offers actions for the thing you pointed at, opening at the pointer. A good one also works without a mouse: the Menu key or Shift plus F10 opens it, arrow keys move through items, Enter chooses, and Escape closes it and returns focus. It must stay inside the screen and never replace the only way to reach an action.

Purpose & UX principles

  • Open on contextmenu, on a long press for touch, and on the keyboard shortcut.
  • Use role menu and role menuitem; move focus into the menu and use arrow keys.
  • Close on Escape, outside click, scroll and choosing an item, and return focus to the trigger.
  • Flip or shift the menu so it stays within the viewport.

Interaction states

  • A file card to right-click, long-press or focus and press the Menu key.

Motion specification

  • The menu appears instantly.
  • Reduced motion: nothing animates.

Responsive behaviour

  • Always provide the same actions elsewhere, because many people never discover right-click.
  • Place dangerous actions last and style them clearly.

Code

HTML
<div class="bx"><div class="ar" id="ar" tabindex="0" aria-label="File: report.pdf. Press the Menu key or Shift plus F10 for actions."><span class="ic">PDF</span><b>report.pdf</b><small>Right-click, long-press, or press the Menu key</small></div><ul class="mn" id="mn" role="menu" aria-label="File actions" hidden><li role="none"><button role="menuitem" tabindex="-1">Open</button></li><li role="none"><button role="menuitem" tabindex="-1">Rename</button></li><li role="none"><button role="menuitem" tabindex="-1">Duplicate</button></li><li role="separator"></li><li role="none"><button role="menuitem" tabindex="-1" class="dg">Delete</button></li></ul><p class="out" id="out" role="status"></p></div>

Related patterns

Dropdown Menu

↗
Dropdown MenuOverlays & Dialogs

Anchored Popover

↗
Anchored PopoverOverlays & Dialogs

Long Press Menu

↗
Long Press MenuGestures & Touch