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
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 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.<T> Action.Input<T> Returns anAction.Inputthat yieldsevent[name]at fire time — the value of a property on the DOM event object.
-
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
-
property
Returns anAction.Inputthat yieldsevent[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
IllegalArgumentExceptionat theTrigger.triggers(Action...)call site.- Type Parameters:
T- the runtime type of the value produced- Parameters:
name- the event property name (e.g."screenX","key"), notnull- Returns:
- an input that resolves to
event[name]on fire
-
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 call
getHost().addJsInitializerwith an install expression that hands the actionJsFunctionto whatever client API the trigger wraps:
The expression runs withreturn getHost().addJsInitializer( "this.addEventListener($1, $0);" + "return () => this.removeEventListener($1, $0);", action, eventName);thisbound to the host element. The captures 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
-