import * as React from 'react'; import Menu from '@mui/material/Menu'; import MenuItem from '@mui/material/MenuItem'; import Typography from '@mui/material/Typography'; export default function ContextMenu() { const [contextMenu, setContextMenu] = React.useState(null); const handleContextMenu = (event) => { event.preventDefault(); setContextMenu( contextMenu === null ? { mouseX: event.clientX + 2, mouseY: event.clientY - 6, } : // repeated contextmenu when it is already open closes it with Chrome 84 on Ubuntu // Other native context menus might behave different. // With this behavior we prevent contextmenu from the backdrop to re-locale existing context menus. null, ); // Prevent text selection lost after opening the context menu on Safari and Firefox const selection = document.getSelection(); if (selection && selection.rangeCount > 0) { const range = selection.getRangeAt(0); setTimeout(() => { selection.addRange(range); }); } }; const handleClose = () => { setContextMenu(null); }; return (