Skip to content

Context Menu

<loomi-context-menu> gives any region a Loomi-styled right-click action menu. It follows the same visual language and item API as <loomi-dropmenu>, but opens from the pointer or keyboard context-menu gesture instead of a trigger button.

Terminal window
npm install @loomidev/context-menu lit
import "@loomidev/context-menu";

Put the right-click target in the target slot and menu actions in the default slot.

Right-click this file
Duplicate Rename Delete
<loomi-context-menu>
<div slot="target">Right-click this file</div>
<loomi-context-menu-item icon="document-duplicate">Duplicate</loomi-context-menu-item>
<loomi-context-menu-item icon="pencil-square" shortcut="E">Rename</loomi-context-menu-item>
<loomi-context-menu-item divider></loomi-context-menu-item>
<loomi-context-menu-item icon="trash">Delete</loomi-context-menu-item>
</loomi-context-menu>

Keyboard users can focus the target and press the Context Menu key or Shift+F10.

<loomi-context-menu-item> supports the same core item affordances as dropmenu:

Project View profile Support Documentation Contact support
<loomi-context-menu>
<button slot="target">Actions</button>
<loomi-context-menu-item header>Project</loomi-context-menu-item>
<loomi-context-menu-item icon="user" shortcut="⌘K P">View profile</loomi-context-menu-item>
<loomi-context-menu-item icon="question-mark-circle">
Support
<loomi-context-menu-item slot="submenu">Documentation</loomi-context-menu-item>
<loomi-context-menu-item slot="submenu">Contact support</loomi-context-menu-item>
</loomi-context-menu-item>
</loomi-context-menu>

The menu is positioned against the viewport (position: fixed) at the pointer, so no ancestor’s overflow clips it.

A submenu is a floating panel in its own right, on the same terms: it opens beside the row that owns it, flips to that row’s left when it would run off the right of the screen, slides up when it is taller than the room beneath the row, and is in the top layer — so scrollable menus don’t clip it either. A nested submenu follows whichever side its parent settled on, rather than zig-zagging back across it.

The resolved side is published as data-side="left" | "right" on the submenu, and the submenu is exposed as the submenu part.

Submenus open on hover and on keyboard focus, and close a moment after the pointer leaves both the row and the panel — the delay is what lets you cross the gap between them.

For the library-wide baseline, see Foundations — Accessibility.

For the shared container and viewport rules, see Foundations — Responsive behavior.

For theme activation, token overrides, and contrast guidance, see Foundations — Dark mode.

AttributeDefaultDescription
disabledfalsePrevents opening the menu.
dividedfalseAdds dividers between direct child items.
placementautoHorizontal alignment from the pointer: auto, left, or right.
scrollablefalseConstrains the menu height and scrolls its contents.
height200Scrollable menu height in pixels.
hide-after-clicktrueCloses after a selectable item without a submenu is clicked.
icon-rightfalsePlaces item icons on the right unless an item overrides it.
AttributeDefaultDescription
icon(blank)Loomi icon name.
shortcut(blank)Shortcut text shown at the trailing edge.
icon-rightfalsePlaces this item’s icon on the right.
headerfalseRenders non-selectable section text.
dividerfalseRenders a separator line.
hovertrueEnables hover/focus background styling.
SlotDescription
(default)Content placed inside the component.
submenuNested menu items.
targetThe element that opens the context menu.
MethodDescription
showAt(clientX, clientY)Opens the menu at viewport coordinates.
hide()Closes the menu.

The component understands its own CSS variables and the dropmenu variables where that keeps visual compatibility useful.

VariableDefault
--loomi-context-menu-z-indexvar(--loomi-dropmenu-z-index, 1000)
--loomi-context-menu-min-widthvar(--loomi-dropmenu-min-width, 13.5rem)
--loomi-context-menu-hovervar(--loomi-dropmenu-hover, ...)
--loomi-context-menu-submenu-min-widthvar(--loomi-dropmenu-submenu-min-width, 12rem)
Terminal window
pnpm --filter @loomidev/context-menu build
pnpm --filter @loomidev/context-menu typecheck
  • @loomidev/core
  • @loomidev/icons