Forum Discussion
cbakerthrive
May 02, 2022Copper Contributor
Adding copy and paste to context menu on Teams
I'm working on a project that uses SharePoint framework (React, etc...) and is used in the Teams environment on both desktop and browser. I'm trying to implement a Context/Right click menu that featu...
Prasad_Das-MSFT
Microsoft
May 17, 2022To render the menu, you can listen to the contextmenu
event, which is triggered by right clicking. Then you can render a custom menu.
The copy/paste etc is probably done using document.execCommand()
, which can be used to trigger copy/paste and such. Check your browser to see which commands are supported.
https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand
// on right click, copy to clipboard.
document.querySelector('body').addEventListener('contextmenu', function( event ) {
// prevent the normal context menu from popping up
event.preventDefault();
// copy current selection
document.execCommand('copy');
});
Thanks,
Prasad Das
------------------------------------------------------------------------------------------
If the response is helpful, please click "**Mark as Best Response**" and like it. You can share your feedback via Microsoft Teams Developer Feedback link. Click here to escalate.