ClipboardController
Purpose
Controller for adding 'copy-to-clipboard' functionality to a link/button/etc, with support for progressive enhancement.
If 'copy' is supported, the controller will select the contents of the given input and execute a "copy".
If 'copy' is NOT supported by the browser the controller will simply select the contents of the given input for the user to be able to copy manually.
You can also wire up the controller to have a copy button, and an optional fallback button (i.e. "Select this text") to show if clipboard controls are not supported by the user's browser. Setting the removeUnused
value to true
will make the controller remove whichever target is unused.
Actions
Action | Purpose |
---|---|
select | Selects the content of the source target |
copy | Selects the content of the source target, and executes a copy, if supported |
Targets
Target | Purpose | Default |
---|---|---|
source | The <input> , <select> or <textarea> to select/copy the value from | - |
copy (Optional) | The element to remove if removeUnused value is true and copy is supported | - |
fallback (Optional) | The element to remove if removeUnused value is true and copy is not supported | - |
Classes
Class | Purpose | Default |
---|---|---|
- | - | - |
Values
Value | Type | Description | Default |
---|---|---|---|
removeUnusedValue | Boolean | If copy is not supported by the browser, remove the copy target from the DOM. Otherwise remove the fallback target | false |
Events
Event | When | Dispatched on | event.detail |
---|---|---|---|
- | - | - | - |
Side Effects
None