UI + UX Disclosure And Attention Management standard

Context menu

Provide a compact command menu that opens from the invoked object or selection by pointer and keyboard context-menu requests, keeps the target visibly selected, moves focus into the menu, supports menu keyboard behavior, and returns focus to the target on close.

Decision first

Choose this pattern when the problem matches

Use when

  • Objects or selections have secondary commands that experienced users expect near the target.
  • The command set depends on the invoked object, pointer location, selected set, or focused item.
  • The product can provide keyboard-equivalent invocation and focus behavior.
  • Important commands also remain available through visible controls, menus, shortcuts, or documentation.

Avoid when

  • The command is primary, urgent, safety-critical, or required for task completion.
  • Users are choosing form values or editing content inside the layer.
  • The product cannot support keyboard context-menu invocation and focus return.
  • The action set is product-wide rather than tied to a target object or selection.
  • The menu would contain long content, filters, previews, or multi-step workflows.

Problem it prevents

Objects often have secondary commands that experienced users expect near the object, but hiding commands behind pointer-only right click or stale context can make actions undiscoverable, target-ambiguous, or inaccessible.

Pattern anatomy

What a strong implementation has to make clear

User need

A file, row, canvas object, map item, text selection, card, or selected set has several commands that are useful but not always worth visible space.

Pattern promise

Provide a compact command menu that opens from the invoked object or selection by pointer and keyboard context-menu requests, keeps the target visibly selected, moves focus into the menu, supports menu keyboard behavior, and returns focus to the target on close.

Required state

Resting object or selection state before invocation.

Recovery path

The menu opens for a stale selected object instead of the object under the pointer.

Access contract

Support keyboard invocation through the context-menu key or Shift+F10 where the platform expects it.

Quality bar

The difference between expert and weak execution

Strong implementation

Specific, visible, recoverable

  • A file row opens a context menu at the selected row with Open, Rename, Duplicate, Download, Archive, and Delete separated at the end.
  • A canvas shape opens a context menu at the pointer with Bring forward, Send backward, Duplicate, Lock, and Delete shape, while the selected shape remains highlighted.
  • Right click on Forecast.xlsx opens commands for that file, Arrow keys move through items, Escape closes the menu, and focus returns to the file row.
  • Shift+F10 on the focused file opens the same eligible commands at the row, including disabled Export with a reason and Delete routed to review.
Weak implementation

Vague, hidden, hard to recover from

  • Right clicking a row opens a menu beside the toolbar and still shows actions for the previously selected row.
  • A hidden context menu is the only place to find primary commands such as Save, Submit, or Continue.
  • Keyboard invocation opens at the top-left corner with no visible relationship to the focused object.
  • Long press opens commands that differ from right click, so users cannot predict which action set applies.
UI guidance
  • Render a context menu as a compact command menu anchored to the object, selection, pointer position, or focused item that invoked it, with clear item labels, disabled reasons, separators, and destructive separation.
  • Keep context-menu content to commands or command-like links that apply to the invoked target; do not turn it into a form, preview panel, navigation drawer, or general overflow bucket.
UX guidance
  • Use a context menu when users need fast object-specific commands from a secondary invocation path such as right click, long press, context-menu key, or Shift+F10.
  • Make the same target, command eligibility, keyboard focus, dismissal, and focus return work for pointer and keyboard invocation, and keep important commands available through visible routes too.
Implementation contract

What the implementation must handle

States

  • Resting object or selection state before invocation.
  • Pointer-invoked open state anchored to the object or pointer coordinate.
  • Keyboard-invoked open state anchored to the focused object or selection, not stale pointer coordinates.
  • Visible target state showing which object or selected set commands will affect.

Interaction

  • The menu opens only for the object, selection, or location that invoked it.
  • Pointer and keyboard invocation expose the same applicable commands for the same target.
  • The invoked target remains highlighted, focused, or otherwise visibly identified while the menu is open.
  • Opening moves focus into the menu or sets an active descendant so Arrow keys operate inside the command list.

Accessibility

  • Support keyboard invocation through the context-menu key or Shift+F10 where the platform expects it.
  • Open keyboard-invoked menus at the focused target or selected object.
  • Use accessible names that identify the target or selected set.
  • Move focus into the menu and expose active item state when using menu semantics.

Review

  • What exact object, selection, or location invoked this context menu?
  • Can users access the same important command through a visible route?
  • Does keyboard invocation open at the focused object with the same eligible commands as pointer invocation?
  • How are stale selection, target removal, viewport collision, and scroll handled?
Interactive lab

Inspect the states before you copy the pattern

Invoke object commands from pointer or keyboard context

Right-click or use Shift+F10 on a file row, verify the menu opens at the invoked file, move through commands, try a disabled export reason, dismiss with Escape, route Delete to review, and compare stale-target, keyboard-corner, hidden-primary, mixed-content, pointer-keyboard-mismatch, and focus-loss failures.

Context menu
Interactive demo is ready

Launch the live UI/UX lab when you want to inspect states, keyboard behavior, and common failure modes.

State To Inspect

Resting object or selection state before invocation.

Keyboard / Access

Context-menu key or Shift+F10 opens the menu for the focused object or selected set.

Avoid Generating

Making right click or long press the only way to discover important commands.

Evidence trail

Source-backed claims behind this guidance

Element: contextmenu event

MDN Web Docs - checked

Supports right-click and context-menu-key invocation plus compatibility cautions.

Fluent 2 Menu

Microsoft Fluent 2 Design System - checked

Supports menus as hidden lists for immediate actions or navigation rather than input collection.

Full agent/debug reference

Problem Context

  • A file, row, canvas object, map item, text selection, card, or selected set has several commands that are useful but not always worth visible space.
  • Users may invoke commands through right click, secondary click, long press, context-menu key, Shift+F10, or another platform-specific request.
  • The target object, selected set, pointer location, permission state, and object state determine which commands are available.
  • Important commands still need visible or documented access because context menus are secondary and less discoverable.

Selection Rules

  • Choose context menu when commands are specific to the object, selection, or location where the user invoked the menu.
  • Use action menu when the main work is designing the command taxonomy, grouping, disabled reasons, destructive handoff, and scope labels independent of invocation method.
  • Use menu button when users need a visible named trigger for the same short command list.
  • Use popover when the anchored layer needs contextual information, controls, or light editing instead of menuitem command activation.
  • Use visible buttons for primary, frequent, safety-critical, or onboarding commands that users should not have to discover through secondary invocation.
  • Use command palette when commands are product-wide, searchable, shortcut-driven, or not tied to the current object.
  • Use native browser or platform context menu when the product does not need custom object-specific commands.
  • Use a confirmation dialog, undo, or review flow after high-risk context-menu commands rather than running them silently.

Required States

  • Resting object or selection state before invocation.
  • Pointer-invoked open state anchored to the object or pointer coordinate.
  • Keyboard-invoked open state anchored to the focused object or selection, not stale pointer coordinates.
  • Visible target state showing which object or selected set commands will affect.
  • Menu focus state with active item, Arrow key movement, Enter or Space activation, and Escape dismissal.
  • Disabled or unavailable item state with reason when the user can recover.
  • Destructive item state separated from safe commands and routed to review or recovery.
  • Dismissed state that returns focus to the invoking object or selected set.
  • Target changed or selection changed state that closes or recalculates the command set.
  • Touch or long-press state with equivalent command availability where the platform supports it.

Interaction Contract

  • The menu opens only for the object, selection, or location that invoked it.
  • Pointer and keyboard invocation expose the same applicable commands for the same target.
  • The invoked target remains highlighted, focused, or otherwise visibly identified while the menu is open.
  • Opening moves focus into the menu or sets an active descendant so Arrow keys operate inside the command list.
  • Escape, outside click, scroll away, or target removal closes the menu without running a command.
  • Safe activation closes the menu and reports what happened to the target.
  • High-risk activation moves to confirmation, undo, restore, or review with the affected target named.
  • Focus returns to the invoking target or a logical replacement after dismissal or activation.
  • The context menu is not the only route to important commands.
  • The menu content stays command-like and does not contain forms, pickers, embedded editors, or long explanatory panels.

Implementation Checklist

  • Define which objects or selections can invoke a context menu and which commands apply to each state.
  • Handle pointer secondary-click, keyboard context-menu key, Shift+F10, and touch or long-press where supported.
  • Anchor pointer menus to the invoked object or pointer and keyboard menus to the focused target.
  • Keep the target visibly selected or focused while the menu is open.
  • Use menu roles and menuitem semantics only when implementing full menu keyboard behavior.
  • Implement Arrow keys, Home, End, typeahead when useful, Enter, Space, Escape, outside dismissal, and focus return.
  • Recalculate or close the menu if selection, target state, permission, or viewport position changes.
  • Expose unavailable commands with reasons when users can act on the reason.
  • Keep primary commands visible elsewhere and document advanced shortcuts where appropriate.
  • Test repeated rows, stale selection, keyboard invocation placement, touch invocation, zoom, clipping, portal placement, screen readers, and destructive handoff.

Common Generated-UI Mistakes

  • Making right click or long press the only way to discover important commands.
  • Opening a context menu for the wrong row because selection and pointer target are out of sync.
  • Ignoring keyboard context-menu invocation or placing the menu at a stale pointer coordinate.
  • Showing different command sets for right click and Shift+F10 on the same object.
  • Using a context menu as a catch-all for global navigation, filters, forms, previews, and settings.
  • Running destructive commands immediately from the menu without confirmation, undo, or object-specific review.
  • Leaving focus behind the menu so Arrow keys scroll the page or move the selected object.
  • Letting menus remain open after the target disappears, scrolls away, or changes state.

Critique Questions

  • What exact object, selection, or location invoked this context menu?
  • Can users access the same important command through a visible route?
  • Does keyboard invocation open at the focused object with the same eligible commands as pointer invocation?
  • How are stale selection, target removal, viewport collision, and scroll handled?
  • Are commands scoped, labelled, grouped, disabled, and risk-separated according to action-menu rules?
  • Where does focus go on open, Arrow navigation, Escape, outside click, safe activation, and destructive handoff?
Accessibility
  • Support keyboard invocation through the context-menu key or Shift+F10 where the platform expects it.
  • Open keyboard-invoked menus at the focused target or selected object.
  • Use accessible names that identify the target or selected set.
  • Move focus into the menu and expose active item state when using menu semantics.
  • Return focus to the invoking target or its logical replacement after close.
  • Keep visible item labels aligned with accessible names and object scope.
  • Expose disabled states and reasons without relying on color alone.
  • Provide visible alternatives for important commands so context menus are not the only accessible path.
Keyboard Behavior
  • Context-menu key or Shift+F10 opens the menu for the focused object or selected set.
  • Arrow Down and Arrow Up move between menu items.
  • Home and End move to the first and last menu item when implemented.
  • Enter or Space activates the focused command unless disabled.
  • Escape closes the menu and returns focus to the invoking target.
  • Tab closes the transient menu according to the chosen menu implementation.
  • Printable character keys may move to the next matching item when typeahead is implemented.
  • After destructive selection, focus moves to the review or confirmation surface with the target named.
Variants
  • Right-click context menu
  • Keyboard context menu
  • Long-press context menu
  • File context menu
  • Table row context menu
  • Canvas object context menu
  • Text selection context menu
  • Map marker context menu
  • Bulk selection context menu

Verification

Last verified: