Skip to main content

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

ActionPurpose
selectSelects the content of the source target
copySelects the content of the source target, and executes a copy, if supported

Targets

TargetPurposeDefault
sourceThe <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

ClassPurposeDefault
---

Values

ValueTypeDescriptionDefault
removeUnusedValueBooleanIf copy is not supported by the browser, remove the copy target from the DOM. Otherwise remove the fallback targetfalse

Events

EventWhenDispatched onevent.detail
----

Side Effects

None

How to Use