Skip to content
Razor catalogue

On this page

@addTagHelper *, Webority.Ui.Razor

Around a region

Wrap a card, panel or list to give everything inside it a right-click menu, with no extra layout.

A card with row actions
Right-click the region. The disabled row is listed but skipped by the arrow keys. ArrowDown and ArrowUp move between rows and wrap; Home and End jump to the first and last; typing the start of a label jumps to it; Enter or Space chooses; Escape closes and returns focus to where it was; Tab closes. A click outside, a scroll of the page, a resize and a switch to another window all close it. The keyboard opens the menu from the focused element, so the region needs something focusable inside it (a link, a button, or a row with tabindex 0). A menu is also a shortcut, never the only way to an action: keep the same actions reachable from a visible button or an <code>&lt;app-dropdown&gt;</code>.
Q3 reportAsha
Launch planRavi
Design briefMeera

Nothing chosen yet.

Show code
<app-context-menu aria-label="Card actions">
    <app-card>…</app-card>
    <app-context-menu-item key="open" label="Open" icon="eye" />
    <app-context-menu-item key="archive" label="Archive" disabled="true" />
    <app-context-menu-divider />
    <app-context-menu-item key="delete" label="Delete" icon="trash-2" tone="Tone.Danger" />
</app-context-menu>

Table rows

Use one menu for a whole table, so each row shares it and onOpen tells each action which row it acts on.

One menu for every row
Right-click a row. The select event carries the row and the key of the action chosen.
DocumentOwner
Q3 reportAsha
Launch planRavi
Design briefMeera

Nothing chosen yet.

Show code
<table id="orders">…<tbody><tr data-id="42">…</tr></tbody></table>

<app-context-menu id="rowMenu" target="#orders tbody tr" aria-label="Order actions">
    <app-context-menu-item key="open" label="Open" icon="eye" />
    <app-context-menu-item key="delete" label="Delete" icon="trash-2" tone="Tone.Danger" />
</app-context-menu>

<script>
    document.getElementById('rowMenu').addEventListener('wui-context-menu:select', function (e) {
        // e.detail.key: the row chosen; e.detail.region: the matched <tr>
        console.log(e.detail.key, e.detail.region.dataset.id);
    });
</script>

Pointer, touch and keyboard

Pointer, touch and keyboard
A right-click opens at the pointer. A press held for half a second opens at the finger, and cancels if the finger moves, lifts or scrolls. Shift+F10 or the ContextMenu key opens under the focused element, with the first row focused.
Right-click here
Show code
<app-context-menu aria-label="Card actions">
    <div class="border rounded p-4 text-center text-muted" tabindex="0">Right-click here</div>
    <app-context-menu-item key="open" label="Open" icon="eye" />
    <app-context-menu-item key="delete" label="Delete" icon="trash-2" tone="Tone.Danger" />
</app-context-menu>

Every option

Every value of every prop, one cell each.

items

labels only
Right-click here
icon
Right-click here
image
Right-click here
danger
Right-click here
disabled
Right-click here
divider
Right-click here
shortcut: a key hint at the row end
Right-click here
href (a link row, React: to)
Right-click here
hint and checked
Right-click here
app-context-menu-submenu
Right-click here
searchable submenu
Right-click here

target

target="[data-row]" (one menu serves every match)
Row one
Row two

trigger

no trigger (default)
Right-click here
trigger="[data-more]" (a button opens it too)
Q3 report

children

children: the region the menu wraps
A card, panel or list

ariaLabel

aria-label: names the menu for screen readers (default "Context menu")
Right-click here

disabled

disabled: false (default)
Right-click here
disabled="true" (the browser's menu shows)
Right-click: no custom menu

open

open: false (default)
Right-click here
open="true" (the panel shows open, for a design preview)
Right-click here

menuClassName

menu-class: adds classes to the panel (here "shadow-lg")
Right-click here

onOpen

onOpen: the wui-context-menu:open event (region, origin, x, y), no visible change
Right-click here

onBeforeOpen

onBeforeOpen: a wui-context-menu:beforeopen listener; preventDefault keeps the menu closed
Right-click: the menu stays closed

linkComponent

linkComponent (React only): Razor writes href, a plain link
Right-click here

Guidance

What to do, and what to avoid.

Use it when

  • A table row, file or card has several actions and a visible button on each would clutter it.
  • Power users expect right-click on a list of records, as in a file manager or a mail client.
  • The same actions are also reachable some visible way.

Reach for something else when

  • The actions hang off a visible button or icon. → AppDropdown
  • You are choosing a value for a form field. → AppSelect
  • The panel holds a form or rich content. → AppPopover

Reference

Try every prop, read the full list, and check keyboard and screen reader behaviour.

No trigger A button inside the region
Right-click here
React, generated from the controls
<AppContextMenu
  items={[
    { key: 'open', label: 'Open', icon: 'eye', onClick: open },
    { key: 'rename', label: 'Rename', icon: 'pencil', onClick: rename },
    { key: 'd1', divider: true },
    { key: 'delete', label: 'Delete', icon: 'trash-2', tone: "danger", onClick: remove },
  ]}
>
  <Region />
</AppContextMenu>
Razor, the same props
<app-context-menu>…</app-context-menu>

7 props. The 4 most used come first.

Used on most screens 4 props

PropTypeDefaultDescription
targetdefault - string - CSS selector of the elements the menu serves. Without it, the menu serves children.
triggerdefault - string - A CSS selector inside the region: a click or Enter on a match opens the menu under it.
aria-labeldefault Context menu string Context menu Accessible name of the menu.
disableddefault false bool false Turns the menu off; the browser's own menu shows instead.

Less common 3 props

PropTypeDefaultDescription
opendefault false bool false Shows the panel open, for a design preview or a controlled caller.
menu-classdefault - string - Extra classes on the menu panel.
items / onOpen / linkComponentdefault - - - Razor writes the rows as app-context-menu-item children, listens for the bubbling wui-context-menu:open event (detail.region, detail.origin, detail.x, detail.y), and renders a link row as a plain anchor. On app-context-menu-item: label (required), key (the row's id in the select event; its position when omitted), href (makes the row a link), icon (a library icon name), image (a picture URL shown instead of an icon), tone (danger for a destructive row) and disabled. app-context-menu-divider is a separator. On a row, hint is muted text at its trailing edge and checked ticks it. app-context-menu-submenu takes key, label (required), icon, tone, disabled, searchable and search-placeholder, and holds its own rows and dividers; submenus nest. A row that is an action reaches the page through the bubbling wui-context-menu:select event (detail.key, detail.item, detail.region, detail.origin).

Screen reader

3 notes
  • The menu panel has role menu named by ariaLabel, each row has role menuitem, and a disabled row sets aria-disabled.
  • Arrow keys, Home and End move between rows, typing the start of a label jumps to it, Enter or Space chooses, and Escape closes the menu and returns focus to where it was.
  • Shift+F10 or the ContextMenu key opens the menu under the focused element, and a long press opens it on touch.