Class ClipboardReadAction
java.lang.Object
com.vaadin.flow.component.trigger.internal.Action
com.vaadin.flow.component.trigger.internal.ClipboardReadAction
- All Implemented Interfaces:
Serializable
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.component.trigger.internal.Action
Action.Input<T> -
Constructor Summary
ConstructorsConstructorDescriptionClipboardReadAction(SerializableConsumer<@Nullable ClipboardPayload> handler) Creates an action that reads the user's clipboard and delivers the contents tohandler. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappendStatement(com.vaadin.flow.component.trigger.internal.JsBuilder builder, StringBuilder out) Appends this action's JS statement toout.
-
Constructor Details
-
ClipboardReadAction
Creates an action that reads the user's clipboard and delivers the contents tohandler.- Parameters:
handler- invoked on the UI thread with the clipboard contents, ornullif the read failed; notnull
-
-
Method Details
-
appendStatement
protected void appendStatement(com.vaadin.flow.component.trigger.internal.JsBuilder builder, StringBuilder out) Description copied from class:ActionAppends this action's JS statement toout. Element references must go throughJsBuilder.reference(com.vaadin.flow.dom.Element).- Specified by:
appendStatementin classAction- Parameters:
builder- collects element parameter references, notnullout- buffer to append into, notnull
-