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 through width(), height() and
size() so downstream actions can consume them. The shape of the
value produced by size() matches 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", resize.width()),
new SetPropertyAction<>(heightSpan, "textContent", resize.height()));
For internal use only. May be renamed or removed in a future release.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSizeTrigger(Component host) Creates a size trigger on the given host component's root element. -
Method Summary
Modifier and TypeMethodDescriptionheight()event.height— the element's rounded content-box height in pixels.protected Registrationinstall(JsFunction action) Installs the given rendered action as a client-side listener and returns theRegistrationthat detaches it.size()The synthetic event object as a whole, shaped as{width, height}— Jackson-deserialisable into theSizerecord when consumed by an action that decodes its input on the server.width()event.width— the element's rounded content-box width in pixels.
-
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
-
width
event.width— the element's rounded content-box width in pixels. -
height
event.height— the element's rounded content-box height in pixels. -
size
The synthetic event object as a whole, shaped as{width, height}— Jackson-deserialisable into theSizerecord when consumed by an action that decodes its input on the server. -
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
-