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
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.
- Since:
- 25.2
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDomEventTrigger(Component host, String eventName) Creates a trigger that fires when the host receives a DOM event with the given name. -
Method Summary
Modifier and TypeMethodDescriptionprotected Registrationinstall(JsFunction action) Installs the given rendered action as a client-side listener and returns theRegistrationthat detaches it.
-
Constructor Details
-
DomEventTrigger
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, notnulleventName- the DOM event name (e.g."click","input"), notnull
-
-
Method Details
-
install
Description copied from class:TriggerInstalls the given rendered action as a client-side listener and returns theRegistrationthat detaches it. Called once per action passed toTrigger.triggers(Action...).Implementations typically pass
getHost().addJsInitializeran initializer that hands the actionJsFunctionto whatever client API the trigger wraps. The initializer is declared as a snippet, so that nothing is compiled from a string in the browser:@JsExpression("this.addEventListener($1, $0);" + "return () => this.removeEventListener($1, $0);") JsFunction listenToEvent(JsFunction action, String eventName); // In install, with LISTEN_JS = JsSnippets.of(ListenJs.class) return getHost().addJsInitializer( LISTEN_JS.listenToEvent(action, eventName));The initializer runs withthisbound to the host element, and returns the function that uninstalls it. The arguments of the snippet are made available as$0,$1, ? in the order passed.- Specified by:
installin classTrigger- Parameters:
action- the rendered actionJsFunction; takes one runtime argument namedevent(the trigger's event payload), notnull- Returns:
- the registration whose
Registration.remove()detaches the listener, notnull
-