Class ClipboardReadAction

java.lang.Object
com.vaadin.flow.component.trigger.internal.Action
com.vaadin.flow.component.trigger.internal.ClipboardReadAction
All Implemented Interfaces:
Serializable

public class ClipboardReadAction extends Action
Reads the user's clipboard via navigator.clipboard.read() when the bound trigger fires and delivers the textual contents to the handler on the UI thread.

The Clipboard API requires the call to happen inside a short-lived user gesture (click, key press, …) AND the user to grant the clipboard-read permission — without both, the browser rejects the read. Bind this action to a Trigger that fires during such a gesture, typically a ClickTrigger.

The handler receives a ClipboardPayload with the text/plain and text/html representations of the first clipboard item, or null if the read fails for any reason (permission denied, no item, unsupported browser, …). Error detail is intentionally not exposed — see PromiseAction's subclasses for the success/error-split shape if that distinction matters.


 new ClickTrigger(pasteButton).triggers(new ClipboardReadAction(payload -> {
     if (payload == null) {
         notification.show("Clipboard read denied");
     } else {
         editor.setValue(
                 payload.html() != null ? payload.html() : payload.text());
     }
 }));
 
For internal use only. May be renamed or removed in a future release.
See Also:
  • Constructor Details

    • ClipboardReadAction

      public ClipboardReadAction(SerializableConsumer<@Nullable ClipboardPayload> handler)
      Creates an action that reads the user's clipboard and delivers the contents to handler.
      Parameters:
      handler - invoked on the UI thread with the clipboard contents, or null if the read failed; not null
  • Method Details

    • appendStatement

      protected void appendStatement(com.vaadin.flow.component.trigger.internal.JsBuilder builder, StringBuilder out)
      Description copied from class: Action
      Appends this action's JS statement to out. Element references must go through JsBuilder.reference(com.vaadin.flow.dom.Element).
      Specified by:
      appendStatement in class Action
      Parameters:
      builder - collects element parameter references, not null
      out - buffer to append into, not null