Skip to content

Commit

Permalink
Fix: dropdown menu works perfectly now
Browse files Browse the repository at this point in the history
  • Loading branch information
AryanK1511 committed Oct 7, 2024
1 parent 579253d commit c895af9
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions wren-ui/src/components/diagram/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,29 @@ const ReactFlowDiagram = forwardRef(function ReactFlowDiagram(
setForceRender(!forceRender);
};

const triggerMouseDown = (event: React.MouseEvent | MouseEvent) => {
const mouseDownEvent = new MouseEvent('mousedown', {
bubbles: true,
cancelable: true,
clientX: event.clientX,
clientY: event.clientY,
button: 0,
});
document.dispatchEvent(mouseDownEvent);
};

const isTargetInDropdown = (target: EventTarget | null) => {
const dropdowns = document.querySelectorAll('.ant-dropdown');
return Array.from(dropdowns).some((dropdown) =>
dropdown.contains(target as Node),
);
};

const dispatchMouseEvent = (event: React.MouseEvent | MouseEvent) => {
if (!event.isTrusted || isTargetInDropdown(event.target)) return;
triggerMouseDown(event);
};

return (
<>
<DiagramContext.Provider value={{ onMoreClick, onNodeClick, onAddClick }}>
Expand All @@ -123,6 +146,7 @@ const ReactFlowDiagram = forwardRef(function ReactFlowDiagram(
nodeTypes={nodeTypes}
edgeTypes={edgeTypes}
maxZoom={1}
onPointerDown={(event) => dispatchMouseEvent(event)}
proOptions={{ hideAttribution: true }}
>
<MiniMap style={minimapStyle} zoomable pannable />
Expand Down

0 comments on commit c895af9

Please sign in to comment.