Methane@methane-ui/*
CSS LayoutsComponentsSkillsTheme BuilderGitHub
← All Components

<mth-context-menu>

@methane-ui/ui~9.0 KB brotli (cold + Lit)~2.6 KB marginal

Right-click and programmatic virtual-anchor context menu with nested submenus and OverlayController top-layer fallback.

When NOT to use: Use a lightweight @methane-ui/css layout class instead of a custom element when static CSS suffices.

Live Interactive Preview

Interactive StageLive Custom Element · <mth-context-menu> (@methane-ui/ui)
Right-click anywhere in this boxOr click to open Context Menu
Ready · interact with <mth-context-menu>, or toggle Theme, Direction (LTR/RTL), or props above.

Multi-Framework Playground & Snippets

<script type="module" src="@methane-ui/ui/context-menu"></script>
<mth-context-menu>Example</mth-context-menu>

Properties & Attributes

PropertyAttributeTypeDefaultDescription
openopenbooleanfalseWhether the context menu popup is open.
labellabelstring""Accessible label for the context menu.
forceFallbackforce-fallbackbooleanfalseForces non-top-layer fallback overlay and JS positioning.
items—ReadonlyArray<unknown>[]Structured menu tree supporting separators, shortcuts, and nested submenus.

Events

EventDetail TypeDescription
mth-select{ value: string; label: string }Fired when a leaf menu item is activated.
mth-openvoidCancelable event fired before opening the menu.
mth-after-openvoidFired after the menu opens.
mth-close{ reason: string }Cancelable event fired before closing the menu.
mth-after-close{ reason: string }Fired after the menu closes.

APG Keyboard Matrix

KeyDirectionWhenExpected Behavior
ArrowDownbothopenmoves focus to next enabled menu item
ArrowUpbothopenmoves focus to previous enabled menu item
ArrowRightbothfocused on item with submenuopens nested submenu
ArrowLeftbothinside nested submenucloses nested submenu
Escapebothopencloses context menu and restores focus

Accessibility Checklist

CategoryRequirementVerified By
ariaAll aria-* IDREFs resolve within the same DOM root (ADR-003).scanSameRootAria
focusdelegatesFocus: true with zero host internals.role (ADR-014).lint-plugin & spec-compiler
contrastRenders legible borders, focus outlines, and selection indicators under forced-colors: active.Playwright forced-colors matrix
keyboardImplements all 5 APG keyboard transitions across LTR/RTL.mth-context-menu.spec.test.ts
statesExposes ElementInternals CustomStateSet flags: :state(open).Conformance suite
i18nRoutes 2 UI/ARIA strings through @methane-ui/core i18n catalog.Locale context test