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 940c9f7 commit e9e266f
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions wren-ui/src/components/diagram/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,28 @@ 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) {
const mouseDownEvent = new MouseEvent('mousedown', {
bubbles: true,
cancelable: true,
clientX: event.clientX,
clientY: event.clientY,
button: 0,
});
document.dispatchEvent(mouseDownEvent);
}
if (!event.isTrusted || isTargetInDropdown(event.target)) return;
triggerMouseDown(event);
};


return (
<>
Expand All @@ -137,7 +146,6 @@ const ReactFlowDiagram = forwardRef(function ReactFlowDiagram(
nodeTypes={nodeTypes}
edgeTypes={edgeTypes}
maxZoom={1}
onPaneClick={(event) => dispatchMouseEvent(event)}
onPointerDown={(event) => dispatchMouseEvent(event)}
proOptions={{ hideAttribution: true }}
>
Expand Down

0 comments on commit e9e266f

Please sign in to comment.