728x90
๋ฐ์ํ
https://blog.logrocket.com/creating-react-context-menu/
Creating a React context menu - LogRocket Blog
Explore how to create a React context menu, the shortcuts to activate right-click menus, and how to create a custom context menu Hook.
blog.logrocket.com
// context menu
const [clicked, setClicked] = useState(false);
const [points, setPoints] = useState({ x: 0, y: 0 });
const [selectedTr, setSelectedTr] = useState(null);
<tr
onContextMenu={ (e)=>{
e.preventDefault();
setClicked(true);
setSelectedTr(e.target.parentElement);
setPoints({ x: e.clientX, y: e.clientY });
} } >
<td type="productId" scope="row" className="px-3 py-4">
{ productId }
</td>
</tr>
{clicked && (
<div style={{
position: 'absolute',
top: points.y,
left: points.x,
zIndex: 100,
width: '100px',
backgroundColor: 'rgb(55 65 81)',
borderRadius: '5px',
padding: '5px',
color: 'white',
}}>
<div style={{ borderBottom: '1px solid rgb(100,100,100)', cursor: 'pointer' }} onClick={ ()=>{ console.log(selectedTr) } }>๋ฉ๋ด 1</div>
<div style={{ borderBottom: '1px solid rgb(100,100,100)', cursor: 'pointer' }}>๋ฉ๋ด 2</div>
<div style={{ borderBottom: '1px solid rgb(100,100,100)', cursor: 'pointer' }}>๋ฉ๋ด 3</div>
</div>
)}
728x90
๋ฐ์ํ