Create

Navigation

Context Menu

Copy page View as Markdown Open in ChatGPT Open in Claude

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

Usage#

app.component.ts
import { WdsContextMenuComponent } from '@wds/angular/context-menu';

The menu uses the Dropdown items: wds-dropdown-item, wds-dropdown-label, wds-dropdown-separator, wds-dropdown-group, wds-dropdown-radio-group and a nested wds-dropdown as a submenu. Importing @wds/core/context-menu registers them as well.

Examples#

Default#

The element in the trigger slot is the area. A right click on it (a long press on a touch screen, or the context menu key) opens the menu at the pointer instead of the browser menu; near the edge of the window the menu opens on the other side of the pointer. Selecting an item fires wds-select with its value and closes the menu.

Right click here
Back Forward Reload Save as… Print…

Icons#

An <svg> before the text gets the icon size and spacing.

Right click here
Copy Cut Paste Share Download

Shortcuts#

The shortcut slot shows a keyboard shortcut on the right. It is only displayed: handle the keys yourself.

Right click here
Back⌘[ Forward⌘] Reload⌘R Save as…⇧⌘S Print…⌘P

A nested wds-dropdown with a wds-dropdown-item in its trigger slot opens a submenu on hover, a click or ArrowRight.

Right click here
Back⌘[ Reload⌘R More tools Save page… Create shortcut… Name window… Developer tools Print…⌘P

Labels and groups#

wds-dropdown-label heads a section and wds-dropdown-separator divides sections; wds-dropdown-group with aria-label names a group for screen readers.

Right click here
File New file⌘N Open…⌘O Save⌘S Edit Undo⌘Z Redo⇧⌘Z

Checkboxes#

type="checkbox" toggles checked on selection; detail.checked in wds-select is the new state. inset on the label lines it up with the items.

Right click here
View Show bookmarks bar⇧⌘B Show full URLs Show status bar

Radio group#

Items with type="radio" in a wds-dropdown-radio-group select one value; the group fires wds-change with it.

Right click here
People Pedro Duarte Colm Tuite Jamie Hall

Destructive#

variant="destructive" marks an item that deletes or cannot be undone.

Right click here
Rename Duplicate Delete ⌘⌫

List#

One menu for many items: the contextmenu event reaches the clicked row before the menu opens, so remember which item it is for and act on it in wds-select. The label at the top names the item.

  • report.pdf2.4 MB
  • budget.xlsx840 KB
  • logo.svg12 KB
OpenDuplicateDelete

Right click a file.

In a dialog#

The menu opens in the top layer, so it shows above a modal wds-dialog and a click outside the menu closes only the menu.

Open dialog
Right click here
New folder⇧⌘NUpload files…Sort by name
Close

API References#

wds-context-menu#

A menu that opens at the pointer on a right click (or a long press on touch screens, or the context menu key) over its trigger area, in place of the browser menu. The panel opens in the top layer (Popover API). It uses the dropdown menu items: wds-dropdown-item (also type="checkbox" and type="radio"), wds-dropdown-label, wds-dropdown-separator, wds-dropdown-group, wds-dropdown-radio-group, and a nested wds-dropdown with a wds-dropdown-item in its trigger slot as a submenu. Importing @wds/core/context-menu registers them as well.

Attributes

AttributeTypeDefaultDescription
openbooleanfalseWhether the menu is open. Also set by show(), close() and toggle().
disabledbooleanfalseDisables opening the menu.

Events

EventDescription
wds-open-changeCustomEvent<WdsDropdownOpenChangeDetail>The menu opens or closes.
wds-selectCustomEvent<WdsDropdownSelectDetail>An item is selected (bubbles from wds-dropdown-item).

Methods

MethodDescription
show()Opens the menu at the top-left corner of the trigger area.
showAt(x: number, y: number)Opens the menu at a point in viewport coordinates (clientX, clientY).
close()Closes the menu (with any open submenus).
toggle()Opens or closes the menu.

Slots

SlotDescription
triggerThe area that opens the menu (any element). Keep the same actions reachable another way, e.g. in a toolbar or a dropdown: a right click is not available to every user.
(default)Content: wds-dropdown-item, -label, -separator, -group, -radio-group, submenus.

CSS parts (::part)

PartDescription
contentThe menu panel.

CSS custom properties

PropertyDescription
--wds-dropdown-min-widthMinimum width of the panel (default 8rem).

Accessibility#

Screen reader#

The panel has role="menu"; items have role="menuitem", or menuitemcheckbox / menuitemradio with aria-checked, as in the Dropdown.

The trigger area gets no ARIA attributes: a right click is a shortcut, not the only way to an action. Offer the same actions in a visible control, such as a toolbar button or a dropdown.

When the menu closes after a selection or Escape, focus returns to the element that had it before the menu opened.

Keyboard support#

KeyFunction
Shift+F10ContextMenuOn a focused element in the area: opens the menu below it.
ArrowDownArrowUpMoves focus to the next or previous item, wrapping around; disabled items are skipped.
HomeEndMoves focus to the first or last item.
EnterSpaceSelects the focused item and closes the menu.
ArrowRightOn a submenu trigger: opens the submenu and focuses its first item.
ArrowLeftIn a submenu: closes it and returns focus to its trigger.
EscapeCloses the menu (or the submenu).
A–ZMoves focus to the next item whose text starts with the typed characters.
Footer