Class Clipboard

java.lang.Object
com.vaadin.flow.component.clipboard.Clipboard
All Implemented Interfaces:
Serializable

public final class Clipboard extends Object implements Serializable
Entry point for the browser clipboard API. Bind clipboard actions to a user gesture by chaining off onClick(Component):

 Button copyButton = new Button("Copy");
 Clipboard.onClick(copyButton).writeText(textField);

 Clipboard.onClick(copyButton)
         .write(ClipboardContent.create().text("Hello").html("<b>Hello</b>"));
 
The Clipboard API requires a fresh user gesture for each write, so actions only run during the DOM event that fires the underlying trigger.
See Also:
  • Method Details

    • onClick

      public static <T extends Component & ClickNotifier<?>> ClipboardBinding onClick(T component)
      Registers the given component as a clickable trigger for a clipboard action — the common shape for copy-to-clipboard buttons. Equivalent to new ClickTrigger(component), without making callers reach for the trigger framework's internal types.
      Type Parameters:
      T - the component type, must implement ClickNotifier
      Parameters:
      component - the component to listen for clicks on, not null
      Returns:
      a new binding that can chain actions to this trigger