Skip to content

Radix UI Context Menu Not Working — Fix Right-Click

DodaTech Updated 2026-06-24 1 min read

In this fix, you'll learn how to implement right-click context menus. This matters for power user interactions, and appears in file managers and code editors.

The Problem

The following code demonstrates the typical mistake:

<ContextMenu>
  <div className="target-area">
    Right-click here
  </div>
  <ContextMenuContent>
    <ContextMenuItem>Edit</ContextMenuItem>
    <ContextMenuItem>Delete</ContextMenuItem>
  </ContextMenuContent>
</ContextMenu>
// Right-click shows browser context menu, not Radix menu

The Fix

Here is the corrected version:

<ContextMenu>
  <ContextMenuTrigger className="block p-8 border-2 border-dashed rounded-lg">
    <p>Right-click anywhere in this area</p>
  </ContextMenuTrigger>
  <ContextMenuContent className="w-48">
    <ContextMenuItem inset onClick={() => edit()}>
      <Pencil className="mr-2 h-4 w-4" />
      Edit
    </ContextMenuItem>
    <ContextMenuItem inset onClick={() => delete()}>
      <Trash className="mr-2 h-4 w-4" />
      Delete
    </ContextMenuItem>
    <ContextMenuSeparator />
    <ContextMenuItem inset disabled>
      Properties
    </ContextMenuItem>
  </ContextMenuContent>
</ContextMenu>
// Right-click shows Radix context menu with custom items

Prevention

  • Wrap the trigger target element with ContextMenuTrigger, not just any div.
  • ContextMenuTrigger prevents the browser's default context menu on the wrapped element.
  • Use inset on ContextMenuItem for proper icon spacing.
  • Use ContextMenuSeparator to group related actions.
  • ContextMenuCheckboxItem and ContextMenuRadioItem work inside context menus.

Common Mistakes with ui context menu

  1. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  2. Non-exhaustive pattern matches that compile with warnings then crash at runtime
  3. Misunderstanding that String is [Char] with poor performance for large text operations

These mistakes appear frequently in real-world RADIX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### How does ContextMenuTrigger work?

It intercepts the onContextMenu event (right-click), prevents the default browser menu, and positions the ContextMenuContent at the click location.

Can I have a regular right-click in part of the trigger area?

No — ContextMenuTrigger covers its entire child. For mixed behavior, split the area into separate elements: wrap only the portion that should show the context menu.

Does ContextMenu support submenus?

Yes — use ContextMenuSub, ContextMenuSubTrigger, and ContextMenuPortal > ContextMenuSubContent for nested submenus.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro