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:
ClickTrigger

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

    • property

      public <T> Action.Input<T> property(String name)
      Returns an Action.Input that yields event[name] at fire time — the value of a property on the DOM event object.

      The returned input is only valid in actions wired to this trigger; using it elsewhere throws IllegalArgumentException at the Trigger.triggers(Action...) call site.

      Type Parameters:
      T - the runtime type of the value produced
      Parameters:
      name - the event property name (e.g. "screenX", "key"), not null
      Returns:
      an input that resolves to event[name] on fire
    • installJs

      protected String installJs()
      Description copied from class: Trigger
      Builds the JS expression that installs this trigger's listener and returns a cleanup function that removes it.

      The expression runs with this bound to the host element. The handler JsFunction is available as $0; subclasses pass it to whatever client API the trigger wraps (e.g. this.addEventListener(name, $0)) and reference the same $0 in the cleanup callback to detach it.

      Specified by:
      installJs in class Trigger
      Returns:
      the JS install expression, not null