Switch theme

Examples › Multiple targets

Since its component tree is only created when you right-click on a target element and destroyed when hidden, implementing the context menu functionality on multiple target will not result in performance issues.
In the example below, a single context menu instance is generated when needed and destroyed when hidden:
const showContextMenu = useContextMenu();
return (
<Grid>
{images.map((image, index) => (
<Grid.Col xs={4} key={index}>
<Picture
image={image}
onContextMenu={showContextMenu([
{
key: 'copy',
icon: <IconCopy size={16} />,
onClick: () => copyImageToClipboard(image.file.src),
},
{
key: 'download',
icon: <IconDownload size={16} />,
onClick: () => downloadImage(image.file.src),
},
{ key: 'divider' },
{
key: 'author',
icon: <IconLink size={16} />,
title: `Open ${image.author.name}’s profile`,
onClick: () => window.open(`https://unsplash.com/@${image.author.profile}`, '_blank'),
},
])}
/>
</Grid.Col>
))}
</Grid>
);
Right-click on any image to trigger the context menu:
Picture by Lloyd Henneman | Mantine ContextMenu
Picture by Lloyd Henneman
Picture by Michael Sum | Mantine ContextMenu
Picture by Michael Sum
Picture by Zeke Tucker | Mantine ContextMenu
Picture by Zeke Tucker
Picture by Roberto Huczek | Mantine ContextMenu
Picture by Roberto Huczek
Picture by Nathalie Jolie | Mantine ContextMenu
Picture by Nathalie Jolie
Picture by Manja Vitolic | Mantine ContextMenu
Picture by Manja Vitolic
Picture by Pacto Visual | Mantine ContextMenu
Picture by Pacto Visual
MIT LicenseSponsor the author
Built by Ionut-Cristian Florescu, the author of Mantine DataTable.
Please sponsor my work if you find it useful.
GitHub StarsNPM Downloads