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)

Declarative child-element channel ​

Besides the items JSON, you can declare the menu with <oas-context-menu-item> / <oas-context-menu-group> / <oas-context-menu-divider> child elements (the items attribute wins when set explicitly; otherwise children are parsed and converge to the same rendering path). Default slot text becomes the label; attributes map to the items fields: value / disabled / loading / icon / kind / danger / href / target / rel. Nested elements inside an <oas-context-menu-item> become cascading submenus recursively; an <oas-context-menu-group>'s label is the group title (value can act as a radio-group id) and its children flatten to the same level. Adding/removing children or changing their attributes/text re-renders automatically (MutationObserver).

Declarative children (group / divider / nested / danger / href)

Right-click here to see the declarative menu
CopyPasteNew FileFolderComponent docsDelete
Nothing selected

Dynamic add/remove (MutationObserver auto refresh)

Append an item
Right-click me; click the button above to append an item
CopyPaste

Checkbox and action items (kind) ​

kind="checkbox" renders multi-select checkable items (menuitemcheckbox semantics; clicking toggles and writes back the value array); kind="action" is a pure action item (no check state, never writes back value, only emits the event).

Checkbox + action items (kind)

Right-click to see checkable items

Checked: grid

API ​

oas-context-menu ​

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—
valueChecked set for kind="checkbox" items (JSON array); toggles write back to the host and persist across opensstring—

Events ​

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

Slots ​

NameDescription
defaultContext menu content (items / groups)

CSS Variables ​

CSS VariableDefault
--oas-glass-blurnone
--oas-glass-ringtransparent

oas-context-menu-item ​

Attributes ​

AttributeDescriptionTypeDefault
dangerDestructive item: red semantics (delete/exit etc.)——
disabledDisable this item——
hrefLink address: with href the item renders as a native <a> (real navigation + still emits oas-select)——
iconLeading icon (icon name from the @oas-ui/icons registry)——
icon-colorIcon color: fixes the icon to this color (overrides the selected/disabled default); defaults to currentColor following the text color (only effective via the items JSON channel; the child-element channel does not parse this attribute)——
kindLeaf semantics: radio (default, selectable) / action (no checked state, does not write back value) / checkbox (multi-select, value is the checked-set array)——
loadingLoading: renders a spinner and blocks clicks; recovers when data-driven——
relLink rel (with href)——
shortcutShortcut hint rendered as a trailing kbd (aligned with the menubar/menu shortcut contract) (only effective via the items JSON channel; the child-element channel does not parse this attribute)——
targetLink target (with href)——
valueSelected value (data-carrier field of the declarative child-element channel)——

Slots ​

NameDescription
defaultContext-menu item label content (default slot text); direct child <oas-context-menu-item> elements recursively become the submenu children
template[slot="leading"]Leading media template (or a direct child with slot="leading"): avatars/color chips/any rich leading content, rendered before the label and taking precedence over the icon attribute; replaced by the spinner in the loading state; declarative child channel only (not supported by the items JSON)

oas-context-menu-group ​

Attributes ​

AttributeDescriptionTypeDefault
labelGroup title (small, secondary color, not clickable)——
valueRadio-group id (selecting inside the group only updates that group's value)——

Slots ​

NameDescription
defaultGroup items: child <oas-context-menu-item> elements flatten to the same level

oas-context-menu-divider ​

Slots ​

NameDescription
defaultDivider data carrier (no attributes; the host parses it as type: "divider")

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

Released under the MIT OR Apache-2.0 License.