Search documentation

Find a component or a docs page

Context Menu

Displays a menu to the user — such as a set of actions or functions — triggered by a right click.

Usage

Basic

Right click the trigger, or press the ContextMenu key while it has focus (give it tabindex: 0 if it holds nothing focusable): the menu opens at the pointer and takes focus. Arrow keys, Home/End and typing a letter move through the items; Enter or Space picks one, Esc closes. While it is open the page behind is inert and doesn't scroll.

With shortcuts

ContextMenuShortcut shows the key combination; shortcut: on ContextMenuItem is a shorthand for it. It only displays the keys: binding them is up to you.

With groups

ContextMenuGroup groups items; a ContextMenuLabel inside it names the group for assistive tech.

Checkboxes

ContextMenuCheckboxItem toggles aria-checked and keeps the menu open. Listen to ruby-ui--context-menu:change; event.detail.checked has the new state.

Radio group

ContextMenuRadioItems in a ContextMenuRadioGroup: checking one unchecks the rest. In ruby-ui--context-menu:change, event.detail.value carries the item's value: argument.

Destructive

variant: :destructive marks an item that deletes or can't be undone.

Inset

inset: indents an item or label (pl-8), e.g. to line it up with items that start with an icon.

Side

side: (top, right, bottom, left) and align: (start, center, end) place the menu relative to the pointer; side_offset: and align_offset: set the gap. The defaults are right, start, 0 and 4.

Installation

Components

ComponentBuilt usingSource
ContextMenuPhlex
ContextMenuCheckboxItemPhlex
ContextMenuContentPhlex
ContextMenuDocsPhlex
ContextMenuGroupPhlex
ContextMenuItemPhlex
ContextMenuItemIndicatorPhlex
ContextMenuLabelPhlex
ContextMenuRadioGroupPhlex
ContextMenuRadioItemPhlex
ContextMenuSeparatorPhlex
ContextMenuShortcutPhlex
ContextMenuTriggerPhlex
ContextMenuControllerStimulus JS