@akhatmirzo/ui

ContextMenu

An actions menu opened with a right click (or a long press) — same API and look as DropdownMenu.

Hisobot-2026.pdfO'ng tugma bilan bosing

Import

import { ContextMenu } from '@akhatmirzo/ui';

When to use

  • Quick actions on a file, card or table row — desktop users expect the right click.
  • Only as an extra path. Not everyone discovers right-click menus, and on phones they open with a long press. Make important actions available elsewhere too — a button or a DropdownMenu.
  • Need a menu that opens on a button click? Use DropdownMenu. Both share the same parts, so you can write the actions once and use them in both places.

Anatomy

Parts, props and styles match DropdownMenu (the styles come from a shared module). The difference: Trigger is not a button but the area you right-click, and the panel opens at the pointer.

PartWhat it does
ContextMenuState: onOpenChange, modal, dir
ContextMenu.TriggerThe area (an unstyled <span>; usually with asChild)
ContextMenu.ContentThe panel: portal, opens at the pointer, looping nav
ContextMenu.ItemAn action: icon, shortcut, variant, onSelect
ContextMenu.CheckboxItemA toggleable item (✓)
ContextMenu.RadioGroup / RadioItemOne choice out of several (●)
ContextMenu.Label / Group / SeparatorHeading, group and divider
ContextMenu.Sub / SubTrigger / SubContentA submenu
<ContextMenu>
  <ContextMenu.Trigger asChild>
    <Card>…file…</Card>
  </ContextMenu.Trigger>
  <ContextMenu.Content>
    <ContextMenu.Item icon={<Pencil />} shortcut={['mod', 'E']}>
      Edit
    </ContextMenu.Item>
    <ContextMenu.Separator />
    <ContextMenu.Item variant="danger">Delete</ContextMenu.Item>
  </ContextMenu.Content>
</ContextMenu>

Checkable items

CheckboxItem (checked / onCheckedChange) and RadioGroup (value / onValueChange, or defaultValue) work well for view settings.

Kanvas · 100% — o'ng tugma bilan bosing

Table row: two ways in

Right-click a row for the ContextMenu, or use the "⋯" button for a DropdownMenu with the same actions. Since the part names match, the actions live in a single component. The submenu opens with → or on hover.

  • #1042Dilnoza Karimova1 250 000 so'm
  • #1043Javohir Toshmatov480 000 so'm

On phones

On touch screens the menu opens with a long press. That gesture is hidden, so offer the actions through a visible button as well.

Props

ContextMenu

The Radix ContextMenu Root props: onOpenChange, modal (defaults to true) and dir. The menu opens only from a user gesture.

ContextMenu.Trigger

PropTypeDefaultDescription
asChildbooleanfalseUses the child (a card, a row) as the area
disabledboolean—true — the menu does not open

ContextMenu.Content

Also accepts the rest of the Radix ContextMenu.Content props (alignOffset, onCloseAutoFocus, onEscapeKeyDown ...), <div> attributes and ref.

PropTypeDefaultDescription
collisionPaddingnumber8Minimum distance from the screen edge, px
loopbooleantrue↑ ↓ wrap around from the last item to the first
containerHTMLElement | null—Portal container (defaults to document.body)

ContextMenu.Item

PropTypeDefaultDescription
iconReactNode—Leading icon (16px)
shortcutstring[]—A Kbd label on the right, e.g. ['mod', 'E']
variant'default' | 'danger''default'danger — red text and highlight
onSelect(event: Event) => void—Called on select. preventDefault() keeps the menu open
disabledboolean—Disables the item
asChildbooleanfalseRenders the child (e.g. an <a>) as the item

The props of CheckboxItem, RadioGroup, RadioItem, Sub, SubTrigger and SubContent are the same as in DropdownMenu.

Data attributes

AttributeWhereValue
data-statetrigger, panelopen · closed
data-variantitemdefault · danger
data-highlighteditemunder the keyboard or pointer
data-disableditem, triggerpresent when disabled
data-stateCheckbox/RadioItemchecked · unchecked

Keyboard

KeyAction
Shift + F10Opens the menu on the focused area (browser)
↓ / ↑Move between items (wraps around)
Home / EndFirst / last item
LetterJump to the item starting with that letter
→ / ←Open / close a submenu
Enter / SpaceSelect and close
EscClose

Accessibility

  • Roles. The panel is role="menu", items are menuitem, menuitemcheckbox, menuitemradio. Built on Radix ContextMenu.
  • Hard to discover. A right-click menu is invisible to screen reader and keyboard users — always provide important actions another way too.
  • Shortcuts. With shortcut, the item gets aria-keyshortcuts; the visible Kbd is hidden from screen readers. The label does not listen for the key — wire it up with useHotkeys.
  • Icons are aria-hidden.

On this page