Components/Navigation/Context Menu
COMPONENT38.38

Context Menu

Right-click menu opening at the pointer with flip-on-overflow. Full dropdown item anatomy inside.


INSTALL

1pnpm dlx @sayagodev/mo add context-menu

Or import the files from the package (no copy):

1import "@sayagodev/mo/css/context-menu.css";2import "@sayagodev/mo/js/context-menu.js";

Also copied as dependency: shared.css

EXAMPLES

Basic
Right click here
Checkboxes
Right click here
Radio groups
Right click here
People

Theme
Shortcuts
Right click here
With icons
Right click here
Groups
Right click here
File

Edit


Destructive
Right click here
Submenu
Right click here


Sides
Right click (top)
Right click (right)
Right click (bottom)
Right click (left)

USAGE

1<div data-context-menu>2  <p>Right-click anywhere in here.</p>3  <menu popover id="ctx-1">4    <div data-label>Paper</div>5    <button role="menuitemradio" aria-checked="true">A4</button>6    <hr />7    <button role="menuitem" popovertarget="sub1">More…</button>8    <menu popover id="sub1"><button role="menuitem">Duplicate</button></menu>9  </menu>10</div>

API

NAMEKINDDESCRIPTION
[data-context-menu]attributeContent region; right-click opens the menu at the pointer
menu[popover]elementSurface; nested popovertarget = side submenu
[role=menuitem*]attributeitem · checkbox · radio anatomy as dropdown

FILES

src/css/context-menu.csssrc/js/context-menu.jsdep: src/css/shared.css
Install:mo add context-menu

THEMING · PLAYGROUND

This is the exact component from the examples above, wearing a completely different theme. Edit the tokens and --mo-* hooks in the editor — autocomplete knows them all — and the preview obeys in real time. Your CSS always wins.

Tokens & hooks — edit live
Global tokens
--accent--accent-foreground--border--destructive--foreground--muted-foreground--popover--popover-foreground--radius--ring
Component hooks
--mo-context-menu-min-width--mo-context-menu-outline-color--mo-context-menu-outline-width--mo-context-menu-radius

Preview

Right click here

Your CSS

Try it: type --mo- for the component hooks, or edit any value — the preview obeys in real time.