Tally UI
Primitives

ContextMenu

A menu triggered by right-click or long-press, supporting items, checkboxes, radio groups, and submenus.

Import

import { ContextMenu } from '@tallyui/primitives';

Usage

<ContextMenu.Root>
  <ContextMenu.Trigger>
    <View style={{ padding: 40 }}>
      <Text>Right-click or long-press here</Text>
    </View>
  </ContextMenu.Trigger>
  <ContextMenu.Portal>
    <ContextMenu.Overlay />
    <ContextMenu.Content>
      <ContextMenu.Item>
        <Text>Copy</Text>
      </ContextMenu.Item>
      <ContextMenu.Item>
        <Text>Paste</Text>
      </ContextMenu.Item>
    </ContextMenu.Content>
  </ContextMenu.Portal>
</ContextMenu.Root>

Components

ContextMenu.Root

Manages the open/closed state. Does not render a DOM element.

PropTypeDefaultDescription
openboolean—Controlled open state
defaultOpenbooleanfalseInitial state (uncontrolled)
onOpenChange(open: boolean) => void—Called when open state changes

ContextMenu.Trigger

The area that responds to right-click (web) or long-press (native).

PropTypeDefaultDescription
asChildbooleanfalseMerge props onto child instead of rendering

Plus all React Native PressableProps.

ContextMenu.Portal

Renders children into a portal.

PropTypeDefaultDescription
forceMounttrue—Always mount portal content
hostNamestring—Target portal host name

ContextMenu.Overlay

An optional backdrop behind the menu.

PropTypeDefaultDescription
closeOnPressbooleantrueWhether pressing the overlay closes the menu
forceMounttrue—Always render the overlay
asChildbooleanfalseMerge props onto child instead of rendering

Plus all React Native PressableProps.

ContextMenu.Content

The positioned menu panel. Accepts all PositionedContentProps.

PropTypeDefaultDescription
side'top' | 'bottom''bottom'Preferred side relative to the trigger
sideOffsetnumber0Distance from the trigger
align'start' | 'center' | 'end''center'Alignment along the trigger
avoidCollisionsbooleantrueShift to stay within the viewport
forceMounttrue—Always render the content
asChildbooleanfalseMerge props onto child instead of rendering

Plus all React Native ViewProps.

ContextMenu.Item

A menu action item.

PropTypeDefaultDescription
textValuestring—Text for typeahead search
closeOnPressbooleantrueWhether selecting closes the menu
asChildbooleanfalseMerge props onto child instead of rendering

Plus all React Native PressableProps.

ContextMenu.CheckboxItem

A menu item that toggles a boolean value.

PropTypeDefaultDescription
checkedbooleanrequiredWhether the item is checked
onCheckedChange(checked: boolean) => voidrequiredCalled when checked state changes
textValuestring—Text for typeahead search
closeOnPressbooleantrueWhether selecting closes the menu
asChildbooleanfalseMerge props onto child instead of rendering

Plus all React Native PressableProps.

ContextMenu.RadioGroup

Groups radio items for mutually exclusive selection.

PropTypeDefaultDescription
valuestring | undefinedrequiredThe currently selected value
onValueChange(value: string) => voidrequiredCalled when selection changes
asChildbooleanfalseMerge props onto child instead of rendering

Plus all React Native ViewProps.

ContextMenu.RadioItem

A radio option inside a RadioGroup.

PropTypeDefaultDescription
valuestringrequiredThe value for this option
textValuestring—Text for typeahead search
closeOnPressbooleantrueWhether selecting closes the menu
asChildbooleanfalseMerge props onto child instead of rendering

Plus all React Native PressableProps.

ContextMenu.ItemIndicator

Renders when the parent CheckboxItem or RadioItem is selected.

PropTypeDefaultDescription
forceMounttrue—Always render regardless of selection
asChildbooleanfalseMerge props onto child instead of rendering

Plus all React Native ViewProps.

ContextMenu.Group

Groups related items together.

PropTypeDefaultDescription
asChildbooleanfalseMerge props onto child instead of rendering

Plus all React Native ViewProps.

ContextMenu.Label

A label for a Group.

PropTypeDefaultDescription
asChildbooleanfalseMerge props onto child instead of rendering

Plus all React Native TextProps.

ContextMenu.Separator

A visual divider between items or groups.

PropTypeDefaultDescription
decorativebooleanfalseRemoves from accessibility tree
asChildbooleanfalseMerge props onto child instead of rendering

Plus all React Native ViewProps.

ContextMenu.Sub

A nested submenu root.

PropTypeDefaultDescription
openboolean—Controlled open state
defaultOpenbooleanfalseInitial state (uncontrolled)
onOpenChange(open: boolean) => void—Called when open state changes

ContextMenu.SubTrigger

A menu item that opens a submenu.

PropTypeDefaultDescription
textValuestring—Text for typeahead search
asChildbooleanfalseMerge props onto child instead of rendering

Plus all React Native PressableProps.

ContextMenu.SubContent

The content of a submenu.

PropTypeDefaultDescription
forceMounttrue—Always render the content
asChildbooleanfalseMerge props onto child instead of rendering

Plus all React Native ViewProps.

Accessibility

  • Role: menu on Content, menuitem on Item
  • Triggered by right-click on web, long-press on native
  • Arrow key navigation, typeahead search, and Escape to close on web