Skip to content

Add support for right-click context menu#65

Merged
philippjfr merged 5 commits into
mainfrom
context_menu
May 28, 2026
Merged

Add support for right-click context menu#65
philippjfr merged 5 commits into
mainfrom
context_menu

Conversation

@philippjfr
Copy link
Copy Markdown
Contributor

Description

Adds two features to panel-reactflow:

  1. Node context menus

Adds support for per-node right-click context menus via a new Node.context_menu() method. Users override this method on their Node subclass to return any Panel component, which is rendered as a floating overlay at the click position.

from panel_reactflow import Node, ReactFlow
import panel as pn

class TaskNode(Node):
      def context_menu(self):
            return pn.Column(
                pn.widgets.Button(label="Run"),
                pn.widgets.Button(label="Delete"),
            )

flow = ReactFlow(nodes=[TaskNode(id="t1", position={"x": 0, "y": 0})])
  • Menu appears on right-click, dismissed on pane click
  • Only works for Node subclass instances (dict nodes are ignored)
  • Returning None disables the menu (default behavior)
  • Emits a "node_context_menu" event with node_id and position
  1. Editor rendering optimization

Previously, all node and edge editor views were serialized and sent to the frontend regardless of whether they were visible. This is wasteful, especially in "side" mode where only one editor is shown at a time.

Now:

  • Side mode: Only the selected node/edge editor is sent via a new _selected_editor Child parameter (instead of N editors)
  • Node/toolbar mode: Node editors still sent per-node (all are needed), but edge editors are no longer sent (they were never rendered in these modes)
  • Removed dead JS code (edgeEditorMap, nodeEditorMap, edgeEditors prop on FlowInner)

AI Disclosure

  • Tool & Model: Claude Code + Opus 4.6
  • Usage: Implementation of both features including Python, JSX, CSS, tests, documentation, and examples.
  • I have tested all AI-generated content in my PR.
  • I take responsibility for all AI-generated content in my PR.

Checklist

  • Tests added and are passing
  • Added documentation

@philippjfr philippjfr merged commit 02ed8fe into main May 28, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant