Getting startedComponentsDesign tokensThemingTheme synthesizerFrameworksAccessibilityUtilitiesServer renderingBrowser supportContributingChangelogApp ShellAspect GridAuth ShellCenterContainerDashboard GridFloat BarInsetMasonryPage HeaderPage LayoutResizableResponsive SwitcherSectionSettings LayoutSplit PaneStatus BarStickyToolbarAnchor NavBottom NavBreadcrumbBreadcrumb MenuCommand BarDrawerFooterLinkMenubarNavigation MenuPage IndicatorPaginationRailScroll IndicatorScroll SpyScroll To TopSidebarSkip LinkStepper NavTabsTop BarTree ViewAccordionAspect RatioAvatarAvatar GroupCardCarouselCollapsibleColor SwatchCTA BannerDividerEmpty StateFeature CardIconImageImage CompareImage HotspotsInfinite ScrollLightboxMarqueeQR CodeScroll AreaSkeletonSpinnerStackVideoVirtual ListActivity HeatmapAnimated NumberBadgeBar ListChartClockComparisonCountdown TimerData GridDescription ListDiffGaugeJSON TreeKanbanLevel MeterListMeterSparklineStatStepperTagTimelineUptimeValue CardWaveformBlockquoteCode BlockCode GroupGradient TextHighlightKbdKeyboard MapMarkdownNumber FormatProseTerminalTextTime AgoTruncateTypewriterButtonButton GroupCalendarCheckboxChipColor PickerComboboxCopy ButtonDate PickerDate Range PickerField ListFieldsetFile UploadFormHotkeyIcon ButtonImage CropperInline EditInputInput GroupKnobLabelMasked InputMulti SelectNumber InputPassword InputPin InputRadio GroupRange SliderRatingSearchSegmented ControlSelectSignature PadSliderSortable ListSwitch GroupTag InputTextareaTheme ToggleTime PickerToggleTransfer ListTree SelectAlertAnnouncementBannerCommand PaletteConfirmConnection StatusContext MenuConversationDialogDropdown MenuHover CardLoading OverlayNotification PanelPopoverProgressSheetToastTooltip
ARC UIARC Radiant Components
v4.9DocsComponentsTokensSynthesizer
Getting startedFrameworksServer renderingDesign tokensThemingTheme synthesizerTypographyUtilitiesAll componentsAccessibilityBrowser supportChangelogContributingStatsApp ShellAspect GridAuth ShellCenterContainerDashboard GridFloat BarInsetMasonryPage HeaderPage LayoutResizableResponsive SwitcherSectionSettings LayoutSplit PaneStatus BarStickyToolbarAnchor NavBottom NavBreadcrumbBreadcrumb MenuCommand BarDrawerFooterLinkMenubarNavigation MenuPage IndicatorPaginationRailScroll IndicatorScroll SpyScroll To TopSidebarSkip LinkStepper NavTabsTop BarTree ViewAccordionAspect RatioAvatarAvatar GroupCardCarouselCollapsibleColor SwatchCTA BannerDividerEmpty StateFeature CardIconImageImage CompareImage HotspotsInfinite ScrollLightboxMarqueeQR CodeScroll AreaSkeletonSpinnerStackVideoVirtual ListActivity HeatmapAnimated NumberBadgeBar ListChartClockComparisonCountdown TimerData GridDescription ListDiffGaugeJSON TreeKanbanLevel MeterListMeterSparklineStatStepperTagTimelineUptimeValue CardWaveformBlockquoteCode BlockCode GroupGradient TextHighlightKbdKeyboard MapMarkdownNumber FormatProseTerminalTextTime AgoTruncateTypewriterButtonButton GroupCalendarCheckboxChipColor PickerComboboxCopy ButtonDate PickerDate Range PickerField ListFieldsetFile UploadFormHotkeyIcon ButtonImage CropperInline EditInputInput GroupKnobLabelMasked InputMulti SelectNumber InputPassword InputPin InputRadio GroupRange SliderRatingSearchSegmented ControlSelectSignature PadSliderSortable ListSwitch GroupTag InputTextareaTheme ToggleTime PickerToggleTransfer ListTree SelectAlertAnnouncementBannerCommand PaletteConfirmConnection StatusContext MenuConversationDialogDropdown MenuHover CardLoading OverlayNotification PanelPopoverProgressSheetToastTooltip

Context Menu

Replaces the browser's right-click menu inside one element with a menu of your own items.

ComponentsContext Menu
feedbackinteractive
<arc-context-menu>

Overview

ContextMenu replaces the browser's right-click menu inside one element. It listens for `contextmenu` on its parent, so a right-click anywhere in the parent opens the menu at the pointer, flipped away from the viewport edges. Items are `<arc-menu-item>` children with an optional `icon`, `shortcut` hint and `disabled`. `<arc-menu-divider>` separates them and `<arc-menu-label>` heads a named group. Choosing an item fires `arc-select` with its `value`, or its label if it has none, and closes the menu. Escape or a click outside also closes it. `arc-open` fires on every right-click, including one that only moves an open menu. `arc-close` fires when it closes and is cancelable. The menu takes focus when it opens. Arrow Down and Arrow Up move through the items, skipping dividers and disabled ones, Home and End jump to the first and last, and Enter or Space chooses. Closing from the keyboard returns focus to where it was. A click elsewhere leaves focus where you clicked.

Guidelines

Do

  • Make it a direct child of the element that should get the menu
  • Group related items with `<arc-menu-divider>` or `<arc-menu-label>`, such as clipboard actions and then navigation
  • Show shortcut hints on items that also have a key binding
  • Disable items that don't apply right now instead of removing them, so people learn what the menu offers
  • Give items a `value` when two of them could share a label
  • Move long lists of actions to a CommandPalette

Don't

  • Don't put it on `<body>`. That replaces the browser's menu everywhere on the page
  • Don't put forms or other complex UI in an item. The menu renders its own copy of each item, so only the label, icon and shortcut survive

Features

  • A second right-click while it's open moves the menu to the new spot
  • The `arc-select` detail also has `index`, and an `item` object with the item's `label`, `shortcut`, `icon` and `value`
  • Opens with a scale-in animation

Preview

Right-click anywhere in this box Cut Copy Paste Select all Delete

Usage

This component needs JavaScript. Use the Web Component or a framework wrapper.

<arc-context-menu>
  <div slot="trigger">Right-click me</div>
  <arc-menu-item shortcut="⌘C">Copy</arc-menu-item>
  <arc-menu-item shortcut="⌘V">Paste</arc-menu-item>
</arc-context-menu>

API

openbooleanfalse
Controls the visibility of the context menu. Set to true when the contextmenu event fires; set to false when the user selects an item, clicks the backdrop, or presses Escape.

Events

arc-open
Fired when the context menu opens
arc-close
Fired when the context menu closes
arc-select
Fired when a menu item is selected

MenuItem

<arc-menu-item>

One action in the menu. Its label is the `label` attribute or, without one, its text content.

displayLabel
The text to draw. label was documented as a prop and implemented as a getter over textContent with no setter and no attribute, so <arc-menu-item label="Cut"></arc-menu-item> rendered a blank item, silently, and the six generated wrappers exposed a writable label that did nothing (finding #32). It is a real property now; the text-content form stays the fallback, so every existing consumer is unaffected.
selectionValue
What arc-select reports. Falls back to the label so an item that never sets value behaves as it always did.
labelstring''
Display text for the menu item. Settable, and falls back to the element's text content when unset: <arc-menu-item label="Cut"> and <arc-menu-item>Cut</arc-menu-item> are equivalent.
shortcutstring''
Keyboard shortcut hint displayed on the right side.
iconstring''
Name of the icon to display before the label.
valuestring''
Stable identifier carried on the arc-select detail. Defaults to the label, which is fine until two items share one. Give anything a handler must act on its own value rather than matching against display text.
disabledbooleanfalse
Disables the item, preventing interaction.

MenuDivider

<arc-menu-divider>

A line between groups of menu items.

MenuLabel

<arc-menu-label>

A heading over a group of menu items. The items after it, up to the next label, form one named group.

displayLabel
labelstring''
The heading text. Falls back to the element's text content when unset, as on arc-menu-item.

See also