Class ReplaceChildrenTemporarilyAction
- All Implemented Interfaces:
Serializable
The replacement components are attached as virtual children of the target at construction time, so their DOM is sent to the browser once and the swap on fire is a pure DOM operation. They live as virtual children for the lifetime of the target — fine for a handful of replacements per target, but avoid constructing many short-lived instances.
Slots are handled by the browser. Set slot="…" on the replacement
component's root element if the target uses named slots; the browser's
shadow-DOM slot routing distributes the children when they are appended:
Icon check = new Icon(VaadinIcon.CHECK);
check.getElement().setAttribute("slot", "prefix");
new ClickTrigger(copyBtn).triggers(new ReplaceChildrenTemporarilyAction(
copyBtn, check, new Text("Copied")));
The "original" children are read on the client at the first fire of a cycle,
before the new children are inserted. Rapid re-fires within the timeout
window are coalesced (same semantics as
SetPropertyTemporarilyAction): the original captured on the first
fire is preserved, the replacements are re-applied, and the revert timer is
reset. All ReplaceChildrenTemporarilyActions on the same target share
one stash entry (keyed on "children"), so two such actions in flight
together still restore the truly-original children at the end.
The default timeout is one second (DEFAULT_TIMEOUT).
Duration.ZERO is allowed — the reversion is queued onto the next
event-loop turn, briefly showing the replacement before reverting.
Server-side state is not updated by this action; the changes (both the
temporary swap and the reversion) live in the browser until the next sync
from the client (if any). Plain-text replacements go through Text.
For internal use only. May be renamed or removed in a future release.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.component.trigger.internal.Action
Action.Input<T> -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionReplaceChildrenTemporarilyAction(Component target, Component... replacementChildren) Creates an action that temporarily replaces the children oftargetwithreplacementChildrenwhen the trigger fires, reverting afterDEFAULT_TIMEOUT.ReplaceChildrenTemporarilyAction(Component target, Duration timeout, Component... replacementChildren) Creates an action that temporarily replaces the children oftargetwithreplacementChildrenwhen the trigger fires, reverting aftertimeout. -
Method Summary
Modifier and TypeMethodDescriptionprotected JsFunctionBuilds theJsFunctionthat runs this action when the surrounding trigger fires.Methods inherited from class com.vaadin.flow.component.trigger.internal.Action
applyTemporarily, warnIfNotVisible
-
Field Details
-
DEFAULT_TIMEOUT
Default timeout used by constructors that don't take an explicitDuration: one second.
-
-
Constructor Details
-
ReplaceChildrenTemporarilyAction
Creates an action that temporarily replaces the children oftargetwithreplacementChildrenwhen the trigger fires, reverting afterDEFAULT_TIMEOUT.- Parameters:
target- the component whose children to replace, notnullreplacementChildren- the replacement components; each must not benulland must not already have a parent. An empty array temporarily clears the children.
-
ReplaceChildrenTemporarilyAction
public ReplaceChildrenTemporarilyAction(Component target, Duration timeout, Component... replacementChildren) Creates an action that temporarily replaces the children oftargetwithreplacementChildrenwhen the trigger fires, reverting aftertimeout.- Parameters:
target- the component whose children to replace, notnulltimeout- how long to keep the replacement before reverting, notnulland not negative;Duration.ZEROis allowedreplacementChildren- the replacement components; each must not benulland must not already have a parent. An empty array temporarily clears the children.
-
-
Method Details
-
toJs
Description copied from class:ActionBuilds theJsFunctionthat runs this action when the surrounding trigger fires. The returned function takes one runtime argument namedevent(declared by the framework when it composes the trigger handler); subclasses do not declare argument names themselves.The body is one statement. To embed a value produced on the client, capture an
Action.Input'sJsFunctionas a capture and invoke it inside the body as$N(event).
-