Class DomEventTrigger

java.lang.Object
com.vaadin.flow.component.trigger.internal.Trigger
com.vaadin.flow.component.trigger.internal.DomEventTrigger
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
MouseEventTrigger

public class DomEventTrigger extends Trigger
Fires when the host component receives a DOM event with the given name. The bound actions run inside the browser's event handler, preserving the user-gesture context (so downstream actions may invoke APIs gated on a gesture, such as clipboard or fullscreen).

Examples:


 new DomEventTrigger(button, "click").triggers(action);
 new DomEventTrigger(input, "input").triggers(action);
 new DomEventTrigger(panel, "pointerdown").triggers(action);
 

For internal use only. May be renamed or removed in a future release.

See Also:
  • Constructor Details

    • DomEventTrigger

      public DomEventTrigger(Component host, String eventName)
      Creates a trigger that fires when the host receives a DOM event with the given name.
      Parameters:
      host - the component whose root element listens for the event, not null
      eventName - the DOM event name (e.g. "click", "input"), not null
  • Method Details

    • install

      protected Registration install(JsFunction action)
      Description copied from class: Trigger
      Installs the given rendered action as a client-side listener and returns the Registration that detaches it. Called once per action passed to Trigger.triggers(Action...).

      Implementations typically call getHost().addJsInitializer with an install expression that hands the action JsFunction to whatever client API the trigger wraps:

      
       return getHost().addJsInitializer(
               "this.addEventListener($1, $0);"
                       + "return () => this.removeEventListener($1, $0);",
               action, eventName);
       
      The expression runs with this bound to the host element. The captures are made available as $0, $1, … in the order passed.
      Specified by:
      install in class Trigger
      Parameters:
      action - the rendered action JsFunction; takes one runtime argument named event (the trigger's event payload), not null
      Returns:
      the registration whose Registration.remove() detaches the listener, not null