composite pattern · Menus and navigation
Context Menu
A command menu opened for a specific object or pointer location, commonly by right-click or long press.
Decisive boundary
Provide an equivalent visible and keyboard-accessible path; pointer context cannot be the only route.
Definition and intent
What is a Context Menu UI pattern?
Use the behavior, not the silhouette
A command menu opened for a specific object or pointer location, commonly by right-click or long press. The term is used here as a composite pattern made from multiple controls or regions that must work together. That distinction prevents a visual resemblance from silently deciding focus, keyboard, modality, or dismissal behavior.
Expose commands that apply to a specific object without occupying persistent space. A good implementation preserves that job while making the trigger, open state, close path, and responsive behavior observable to users.
Know when the label is wrong
The fastest way to identify a pattern is often to reject the nearest alternative. For Context Menu, the boundary is: Provide an equivalent visible and keyboard-accessible path; pointer context cannot be the only route.
Do not implement it as Dropdown Menu for general actions and Navigation Menu for destinations. If those requirements describe the real task better, use the related pattern page or the full Menus and navigation comparison before writing code.
Decision process
Decide before choosing a component
Record these requirements in plain language. A library component name is not a substitute for the contract.
Confirm the user job
Expose commands that apply to a specific object without occupying persistent space.
Define opening and closing
Right-click, context-menu key, Shift and F10, long press, or an equivalent visible button. Command activation, Escape, or outside interaction.
Specify access behavior
Managed among menu items and returned to the invoking context. Must have a keyboard trigger and standard menu navigation.
Reject the near miss
Dropdown Menu for general actions and Navigation Menu for destinations.
Behavior contract
What must survive the build
- trigger
- Right-click, context-menu key, Shift and F10, long press, or an equivalent visible button.
- dismissal
- Command activation, Escape, or outside interaction.
- modality
- Transient non-page-blocking menu behavior.
- focus
- Managed among menu items and returned to the invoking context.
- keyboard
- Must have a keyboard trigger and standard menu navigation.
- interactive
- Contains commands relevant to the current object or location.
- persistence
- Temporary while selecting a command.
- placement
- Near the pointer or contextual object.
- mobile
- Long press alone is insufficient; offer a visible actions trigger.
Failure modes
Common wrong builds
- Supporting right-click only.
- Opening browser-hostile custom menus everywhere.
- Failing to restore focus context.
Observable checks
Verify the result
- Keyboard users can open it.
- A visible fallback trigger exists.
- Commands match the object context.
- Escape closes it.
- Focus returns to the invoking object.
Coding-agent handoff
Implementation brief template
Pattern: Context Menu Purpose: Expose commands that apply to a specific object without occupying persistent space. Trigger: Right-click, context-menu key, Shift and F10, long press, or an equivalent visible button. Dismissal behavior: Command activation, Escape, or outside interaction. Modality: Transient non-page-blocking menu behavior. Focus behavior: Managed among menu items and returned to the invoking context. Keyboard behavior: Must have a keyboard trigger and standard menu navigation. Interactive content: Contains commands relevant to the current object or location. Placement: Near the pointer or contextual object. Mobile behavior: Long press alone is insufficient; offer a visible actions trigger. Do not implement as: Dropdown Menu for general actions and Navigation Menu for destinations. Acceptance checks: - Keyboard users can open it. - A visible fallback trigger exists. - Commands match the object context. - Escape closes it. - Focus returns to the invoking object.
Claim-level references
Sources, not a confidence score
Frequently asked questions
Context Menu UI pattern questions
Direct answers based on the reviewed behavior contract above.
What is a Context Menu in web UI?
A command menu opened for a specific object or pointer location, commonly by right-click or long press. In this reference set it is a composite pattern made from multiple controls or regions that must work together.
When should I use a Context Menu?
Expose commands that apply to a specific object without occupying persistent space. The decisive boundary to confirm is this: Provide an equivalent visible and keyboard-accessible path; pointer context cannot be the only route.
What keyboard and focus behavior does a Context Menu need?
Must have a keyboard trigger and standard menu navigation. Managed among menu items and returned to the invoking context. These statements describe the reviewed expectation, but the final implementation still needs testing in the component library and browser you ship.
How should a Context Menu behave on mobile?
Long press alone is insufficient; offer a visible actions trigger. Its modality is a separate requirement: Transient non-page-blocking menu behavior.
How do I verify a Context Menu implementation?
Start with observable checks: Keyboard users can open it. A visible fallback trigger exists. Commands match the object context. Then verify the remaining checks and compare the result with the linked source guidance.