How to pass custom props to ContextMenu2 content? #5744
Unanswered
devinhalladay
asked this question in
Q&A
Replies: 2 comments
-
I was hoping I could do something similar to the advanced context menu render pattern: <ContextMenu2
content={(ctxContentProps) => (
<Menu>
<MenuItem
icon="send-to-graph"
// Access my block prop which was put on the cloned ctxMenuProps.popover
onClick={() => handleBlockClick(ctxContentProps.block)}
text="Add to canvas"
/>
{/* other menu items */}
</Menu>
)}
>
{(ctxMenuProps) => (
<div
className={classNames('grid', ctxMenuProps.className)}
onContextMenu={ctxMenuProps.onContextMenu}
ref={ctxMenuProps.ref}
>
{blocks.map((block) =>
// Clone the popover element and pass the block prop
React.cloneElement(
ctxMenuProps.popover,
{ block: ctxMenuProps.popover }
// block content here
)
)}
</div>
)}
</ContextMenu2>;
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Update: I was able to achieve this by adding a state value that is set within |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Environment
Question
I'm creating a canvas-based PKM tool, and need to add a context menu to every item on the canvas. I've done this by wrapping all the elements in a single
<ContextMenu2 />
with acontent
prop, and using the advanced rendering pattern to provide a custom wrapper for my layout.You'll notice the
blocks.map()
line, which renders the items on the canvas, each of which should have a context menu that passes ablock
prop to the content of the context menu. That way, when the context menu is opened for a block, I can clickDelete block
and have access to its ID in the<Menu />
Is this possible?
Beta Was this translation helpful? Give feedback.
All reactions