-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Description
Feature Description
Currently, the clipboard code from the CDK uses a <textarea> element and calls document.execCommand('copy') on the selected text in the <textarea>. However, this may be troublesome especially if there's a long amount of text to be copied.
What I'm suggesting is to use the Clipboard.writeText method from the Clipboard API.
Here's a description of the Clipboard API:
The Clipboard API provides the ability to respond to clipboard commands (cut, copy, and paste) as well as to asynchronously read from and write to the system clipboard. Access to the contents of the clipboard is gated behind the Permissions API; without user permission, reading or altering the clipboard contents is not permitted.
This API is designed to supersede accessing the clipboard using
document.execCommand(). - from MDN docs for the Clipboard API
Currently, the Clipboard API is supported in the following browsers:
However, according to the MDN docs for "Clipboard availability", it mentions that:
The asynchronous clipboard API is a relatively recent addition, and the process of implementing it in browsers is not yet complete. Due to both potential security concerns and technical complexities, the process of integrating this API is happening gradually in most browsers.
Use Case
This would add another method of copying text instead of the current approach.
