Skip to main content

Overview

Actions extend React Grab with custom functionality accessible from the context menu (right-click) or toolbar dropdown. Actions can perform operations like copying specific formats, opening files, triggering AI agents, or integrating with external tools.

Action Types

React Grab supports two types of actions:
  1. Context Menu Actions - Appear in the right-click context menu when selecting elements
  2. Toolbar Menu Actions - Appear in the toolbar dropdown menu

ContextMenuAction Interface

Context menu actions appear when right-clicking on selected elements:
string
required
Unique identifier for the action
string
required
Display label shown in the context menu
'context-menu'
Set to "context-menu" or omit for context menu actions
string
Keyboard shortcut (single character) to trigger the action. Example: "C" for copy, "O" for open.
boolean | ((context: ActionContext) => boolean)
Whether the action is enabled. Can be a boolean or a function that receives the action context.Example:
(context: ContextMenuActionContext) => void | Promise<void>
required
Callback function executed when the action is triggered.
AgentOptions
Optional AI agent configuration for this action. See Agent Providers for details.

ToolbarMenuAction Interface

Toolbar actions appear in the toolbar dropdown menu:
string
required
Unique identifier for the action
string
required
Display label shown in the toolbar menu
'toolbar'
required
Must be set to "toolbar" for toolbar actions
string
Keyboard shortcut hint (not actively bound, just displayed)
boolean | (() => boolean)
Whether the action is enabled
() => boolean
Function to determine if the action is currently active (shown with a checkmark)
() => void | Promise<void>
required
Callback function executed when the action is triggered

Creating Context Menu Actions

Basic Action

A simple action that logs element information:

Conditional Action

An action that’s only enabled when file path is available:

Action with Feedback

Use performWithFeedback for operations that take time:

Creating Toolbar Actions

Toggle Action

A toolbar action that toggles a state:

Action with Selection

Toolbar action that activates React Grab and waits for element selection:

Complete Action Plugin Example

Here’s a complete plugin with both context menu and toolbar actions:

Action Best Practices

  1. Unique IDs: Use descriptive, unique action IDs to avoid conflicts
  2. Hide Menu: Always call context.hideContextMenu() after completing context menu actions
  3. Cleanup: Call context.cleanup() when deactivating React Grab
  4. Feedback: Use performWithFeedback for async operations to show loading states
  5. Shortcuts: Use single-character shortcuts that don’t conflict with built-in actions
  6. Conditional Enable: Use the enabled function to disable actions when not applicable
  7. Error Handling: Wrap async operations in try/catch blocks

Built-in Action Shortcuts

Avoid conflicting with these built-in shortcuts:
  • C - Copy
  • O - Open in editor
  • Enter - Comment/prompt mode

See Also