Class WebShare

java.lang.Object
com.vaadin.flow.component.webshare.WebShare
All Implemented Interfaces:
Serializable

public final class WebShare extends Object implements Serializable
Entry point for the browser's Web Share API (navigator.share). Two entry points:
  • onClick(Component) — bind a share action to a click gesture. The Web Share API requires a transient user gesture, so the trigger pattern is the only reliable way to invoke it.
  • supportSignal() — feature detection: read whether the current browser exposes navigator.share, useful for deciding whether to show a share affordance at all.

 Button share = new Button("Share");
 if (WebShare.supportSignal().peek() == WebShareSupport.SUPPORTED) {
     WebShare.onClick(share).share(
             ShareContent.create().title("Vaadin").url("https://vaadin.com"));
 }
 
The Web Share API requires a fresh user gesture for each call, so actions only run during the DOM event that fires the underlying trigger.
See Also:
  • Method Details

    • onClick

      public static <T extends Component & ClickNotifier<?>> WebShareBinding onClick(T component)
      Registers the given component as a clickable trigger for a share action — the common shape for "Share" 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
    • supportSignal

      public static Signal<WebShareSupport> supportSignal()
      Returns a read-only signal hinting at whether the Web Share API is available in the current browser for the current UI. The value is seeded from the bootstrap handshake, so user code observes a real value before any view code runs.

      Web Share support is established at page load and does not change during the session, so the signal effectively transitions UNKNOWNSUPPORTED/UNSUPPORTED once and then remains stable.

      Use this to decide whether to show a share affordance at all — calling a share action when the value is WebShareSupport.UNSUPPORTED silently rejects in the browser.

      Returns:
      the read-only support signal
      Throws:
      IllegalStateException - if there is no current UI
    • supportSignal

      public static Signal<WebShareSupport> supportSignal(UI ui)
      Returns a read-only signal hinting at whether the Web Share API is available in the current browser for the given UI. Same semantics as supportSignal(); use this overload from background threads or anywhere UI.getCurrent() is unreliable.
      Parameters:
      ui - the UI to read the hint from, not null
      Returns:
      the read-only support signal
      Throws:
      NullPointerException - if ui is null