Skip to content

ContextMenu

A right-click menu that opens at the mouse position within its wrapped region.

Basic usage

Trigger on right-click

Right-click this area to view the menu

Disabled items

Disabled items

Right-click to view (Delete is disabled)

Nested submenu

Nested submenu

Right-click to view the nested submenu

Items with children expand cascading submenus on hover/click; selecting a leaf item collapses them and closes the menu.

Selection event

Selection event

Right-click this area
Nothing selected

Programmatic positioning & controlled open

show(x, y) / close()

Open at (140, 120)CloseNot open
Right-click this area, or open at arbitrary coordinates via the button above

show(x, y) opens the menu at any coordinates (table rows / canvas / text-selection right-click), close() closes it programmatically; the open attribute controls visibility, and oas-open-change reports the open/close state.

Long-press trigger (mobile)

Mobile devices have no right-click; a long press (500ms by default) opens the menu. long-press-delay adjusts the duration in milliseconds. Verify with DevTools device emulation on desktop.

Long-press trigger

Long-press this area on a touch device

Close on scroll

The menu is fixed-positioned; scrolling the page or an inner scroll container closes it by default (so it never detaches from the content). Set close-on-scroll="false" to disable.

Close on scroll

Right-click to open, then scroll the area below — the menu closes
Right-click me: close-on-scroll="false" stays open on scroll
Scrollable content… (scrolling here while the menu is open closes it automatically)

API

Attributes

AttributeDescriptionTypeDefault
close-on-scrollClose the menu on page scroll (default true)stringtrue
itemsMenu items JSONstring[]
long-press-delayLong-press duration in ms for touch trigger (default 500)string500
openControlled open state (writable externally)boolean

Events

EventDescription
oas-open-changeMenu open state changed, detail: { open: boolean }
oas-selectAn item was selected, detail: { value }

Slots

NameDescription
default

Opens at the mouse position; closes on Esc / outside click / selection; role="menu" + menuitem.

Released under the MIT OR Apache-2.0 License.