Skip to content

ContextMenu

A menu of actions that appears when you right-click an element. The target element has data-ts-context-menu, and the items are the same ones the Menu uses.

Overlays · TaishoDS Core, in plain HTML.

Examples

One working example per case. Each example is the HTML of its preview—copy it as is, and with Core’s CSS and JS loaded, it looks and works the same.

Context menu on a project

Right-click “Payments API”.
html

When to use

  • Offering contextual actions on an item (a row, a file, a card).
  • As a shortcut for power users, on top of a visible path.
  • The actions depend on the element that was right-clicked.

When not to use

  • It would be the only way to reach the action. Right-click isn’t discoverable on its own → add a visible menu.
  • The actions are global, not tied to a specific element → menu or command-palette.
  • Your audience uses touch. Mobile has no right-click, so offer another path.

Do

  • Duplicate anything important in a visible path. The context menu complements; it doesn’t replace.
  • Keep the list short and relevant to what was clicked.

Don’t

  • Don’t make it the only way to do something critical.
  • Don’t replicate the app’s entire menu—only what applies to the element.

TaishoDS Core

Needs Core’s JS, which handles focus, keyboard, and state.

Works like Menu, triggered by a right-click.

Core hooks into it through these attributes. They go in the markup, and there’s nothing to initialize.

  • data-ts-context-menu
  • data-ts-menu
  • data-ts-menu-panel
  • data-ts-value

What it does: Everything Menu does, plus positioning at the pointer’s coordinates, suppressing the browser’s menu, and opening with Shift+F10 or the ContextMenu key (at the bottom-left corner of the area, with focus on the first item).

From the CDN, without a build, load taisho.context-menu.css along with taisho.base.css. That file is all you need.

For how Core works in general, see Behavior.

Accessibility

Implements the Menu Button pattern from the WAI-ARIA APG.

  • A right-click opens it at the cursor position, adjusted so it stays inside the viewport.
  • Keyboard navigation inside the menu, and closing with Esc or a click outside.
  • The items are the same as in the Menu—buttons with role="menuitem", an optional icon, and the variant-danger and is-disabled states.

Keyboard

On top of what the browser already does (Tab moves focus, Enter activates a button).

Key What it does
Shift+F10/“ContextMenu”keyWith focus inside the area, opens the menu at its bottom-left corner and focuses the first item.
↑↓HomeEndMove through the items (with wrapping).
TabCloses the menu, and focus moves on to the next element on the page.
EscCloses the menu and returns focus to whatever had it when the menu opened.

Verification

What was actually tested. Anything that wasn’t tested says so—we’d rather say “not verified” than claim too much.

  • axe WCAG 2.2 A + AA in a real browser, in light and dark mode, before every release.
  • keyboard Key map documented above, checked against the component.
  • screen reader Not verified with a screen reader. Test it in your own combination of components, not just here, where each one appears alone and on its happy path.