Class SizeTrigger
java.lang.Object
com.vaadin.flow.component.trigger.internal.Trigger
com.vaadin.flow.component.trigger.internal.SizeTrigger
- All Implemented Interfaces:
Serializable
Fires when the host component's root element changes size, as reported by the
browser's
ResizeObserver API. The bound actions run inside the
observer callback with a synthetic event whose width and
height hold the rounded pixel size of the element's content box.
The size values are exposed as static Action.Input sources on
SizeTrigger.EventData. The whole-event source SizeTrigger.EventData.size is shaped to
match the Size record so it can be deserialised directly on the
server when forwarded through an action that decodes its input on the server.
Example ? mirror the element's pixel size into two display fields:
SizeTrigger resize = new SizeTrigger(panel);
resize.triggers(
new SetPropertyAction<>(widthSpan, "textContent",
SizeTrigger.EventData.width),
new SetPropertyAction<>(heightSpan, "textContent",
SizeTrigger.EventData.height));
For internal use only. May be renamed or removed in a future release.
- Since:
- 25.2
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe resize-event properties exposed as staticAction.Inputsources. -
Constructor Summary
ConstructorsConstructorDescriptionSizeTrigger(Component host) Creates a size trigger on the given host component's root element. -
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
-
SizeTrigger
Creates a size trigger on the given host component's root element.- Parameters:
host- the component whose root element is observed, 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 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
-