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:- Context Menu Actions - Appear in the right-click context menu when selecting elements
- 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 actionsstring
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 actionsstring
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
UseperformWithFeedback 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
- Unique IDs: Use descriptive, unique action IDs to avoid conflicts
- Hide Menu: Always call
context.hideContextMenu()after completing context menu actions - Cleanup: Call
context.cleanup()when deactivating React Grab - Feedback: Use
performWithFeedbackfor async operations to show loading states - Shortcuts: Use single-character shortcuts that don’t conflict with built-in actions
- Conditional Enable: Use the
enabledfunction to disable actions when not applicable - 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
- Plugins - Plugin system overview
- Agent Providers - AI agent integration
- API Reference - ReactGrabAPI methods
