NativeUI Primitives

Context Menu

Display native context menus with right-click on web and long-press on mobile using one unified API.


Preview

Interactive Demo

Installation

npm install @native-ui-org/primitives
pnpm add @native-ui-org/primitives
yarn add @native-ui-org/primitives
bun add @native-ui-org/primitives

Overview

Context Menu provides platform-native context menus with consistent behavior across all platforms.

FeatureDescriptionPlatforms
ContextMenuNative context menu integrationiOS, Android, Web

Setup & Usage Guide

ContextMenu adapts automatically to each platform's native implementation.

1. Install and Import

Install from npm:

npm install @native-ui-org/primitives

Then import from the package:

import { ContextMenu } from "@native-ui-org/primitives";

2. Basic Usage

Add a context menu to any element:

<ContextMenu
  actions={[
    { title: 'Copy', onPress: () => console.log('Copy') },
    { title: 'Paste', onPress: () => console.log('Paste') },
    { title: 'Delete', onPress: () => console.log('Delete'), destructive: true },
  ]}
>
  <View style={styles.content}>
    <Text>Right-click or long-press me</Text>
  </View>
</ContextMenu>

3. With Icons and Submenus

Add icons and nested menus:

<ContextMenu
  actions={[
    { 
      title: 'Edit', 
      icon: 'edit',
      onPress: () => handleEdit() 
    },
    { 
      title: 'Share',
      icon: 'share',
      children: [
        { title: 'Email', onPress: () => shareEmail() },
        { title: 'Twitter', onPress: () => shareTwitter() },
      ]
    },
    {
      title: 'Delete',
      icon: 'trash',
      destructive: true,
      onPress: () => handleDelete()
    },
  ]}
>
  <View style={styles.card}>
    <Text>Item content</Text>
  </View>
</ContextMenu>

4. Disabled Actions

<ContextMenu
  actions={[
    { title: 'Copy', onPress: handleCopy },
    { title: 'Paste', onPress: handlePaste, disabled: !hasClipboard },
    { title: 'Delete', onPress: handleDelete },
  ]}
>
  <Text>Content</Text>
</ContextMenu>

API Reference

ContextMenu

Container that adds context menu to its children.

PropTypeDefaultDescription
actionsAction[]Required. Menu actions
childrenReact.ReactNodeRequired. Trigger element
titlestringMenu title (mobile only)
disabledbooleanfalseDisable context menu

Action:

PropertyTypeDescription
titlestringRequired. Action label
onPressfunctionAction handler
iconstringIcon name (platform dependent)
destructivebooleanMark as destructive (red on iOS)
disabledbooleanDisable this action
childrenAction[]Submenu items

Platform Behavior

PlatformImplementationCharacteristics
iOSUIContextMenuInteractionNative iOS context menu
AndroidPopupMenuNative Android popup
WebRight-click event + custom menuBrowser context menu override

Triggers:

  • Web: Right-click
  • Mobile: Long-press

Accessibility

All Platforms:

  • Native accessibility built-in
  • Keyboard support on web (context menu key)
  • Screen reader announces menu items

Version History

VersionNotes
0.1.0Initial release — native context menus with unified API.

Summary: ContextMenu provides native context menus across all platforms. Right-click on web, long-press on mobile — same API, same behavior. Perfect for item actions, quick access menus, and contextual operations.