diff --git a/public/app/features/canvas/runtime/scene.tsx b/public/app/features/canvas/runtime/scene.tsx index 1d2aaa63fed..7816c09e62f 100644 --- a/public/app/features/canvas/runtime/scene.tsx +++ b/public/app/features/canvas/runtime/scene.tsx @@ -665,34 +665,36 @@ export class Scene { }; render() { - const canShowContextMenu = this.isPanelEditing || (!this.isPanelEditing && this.isEditingEnabled); const isTooltipValid = (this.tooltip?.element?.data?.links?.length ?? 0) > 0; const canShowElementTooltip = !this.isEditingEnabled && isTooltipValid; + const onSceneContainerMouseDown = (e: React.MouseEvent) => { + // If pan and zoom is disabled or context menu is visible, don't pan + if ((!this.shouldPanZoom || this.contextMenuVisible) && (e.button === 1 || (e.button === 2 && e.ctrlKey))) { + e.preventDefault(); + e.stopPropagation(); + } + + // If context menu is hidden, ignore left mouse or non-ctrl right mouse for pan + if (!this.contextMenuVisible && !this.isPanelEditing && e.button === 2 && !e.ctrlKey) { + e.preventDefault(); + e.stopPropagation(); + } + }; + const sceneDiv = ( - // TODO: Address this eslint error + // The
element has child elements that allow for mouse events, so we need to disable the linter rule // eslint-disable-next-line jsx-a11y/no-static-element-interactions
{ - // If pan and zoom is disabled and middle mouse or ctrl + right mouse, don't pan - if ((!this.shouldPanZoom || this.contextMenuVisible) && (e.button === 1 || (e.button === 2 && e.ctrlKey))) { - e.preventDefault(); - e.stopPropagation(); - } - // If context menu is hidden, ignore left mouse or non-ctrl right mouse for pan - if (!this.contextMenuVisible && e.button === 2 && !e.ctrlKey) { - e.preventDefault(); - e.stopPropagation(); - } - }} + onMouseDown={onSceneContainerMouseDown} > {this.connections.render()} {this.root.render()} - {canShowContextMenu && ( + {this.isEditingEnabled && ( { + // This is disabled when panel is in edit mode because opening inline editor over panel editor is not ideal UX const openCloseEditorMenuItem = !scene.isPanelEditing && ( ); - const setBackgroundMenuItem = !scene.isPanelEditing && ( + const setBackgroundMenuItem = ( {