Class SequenceTrigger
- All Implemented Interfaces:
Serializable
Example:
new SequenceTrigger(layout, Key.KEY_H, Key.KEY_E, Key.KEY_L, Key.KEY_L,
Key.KEY_O).triggers(action);
Listens on keydown. Each key in the sequence matches against
event.key or event.code, so both event.key-named keys (e.g.
Key.ENTER) and event.code-named keys (e.g. Key.KEY_S) work.
Pressing a wrong key resets the position to 0; if that wrong key happens to
match position 0 of the sequence, the position advances to 1 (so
"abab" on a sequence configured as "abab" completes
correctly). There is no timeout — a partial sequence persists across
arbitrarily long gaps until either it completes or a non-matching key
arrives.
Inherits DomEventTrigger.preventDefault() and DomEventTrigger.stopPropagation() from
DomEventTrigger but does not apply them by default — sequences
typically share keys with normal typing and should not swallow every
keystroke.
For internal use only. May be renamed or removed in a future release.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSequenceTrigger(Component host, Key... sequence) Creates a sequence trigger that fires when the given keys are pressed in order onkeydown. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappendHandlerBody(StringBuilder body, List<Object> extraCaptures) Hook for subclasses to contribute statements to the wrapper handler body and extra captures referenced by those statements.protected voidappendInstallPrelude(StringBuilder prelude) Hook for subclasses to inject JavaScript that runs once per install, before theconst h = e => {...}wrapper is created.Methods inherited from class com.vaadin.flow.component.trigger.internal.DomEventTrigger
install, preventDefault, stopPropagation
-
Constructor Details
-
SequenceTrigger
Creates a sequence trigger that fires when the given keys are pressed in order onkeydown.- Parameters:
host- the component whose root element listens for the sequence, notnullsequence- the keys to match, in order; must contain at least one key, none of the entriesnull
-
-
Method Details
-
appendInstallPrelude
Description copied from class:DomEventTriggerHook for subclasses to inject JavaScript that runs once per install, before theconst h = e => {...}wrapper is created. Use this to declare closure variables (e.g.let i = 0;for sequence tracking) that the wrapper body then captures by lexical scope.The prelude has access to the same captures as the rest of the install JS —
$0is the action,$1is the event name, and any extras added viaDomEventTrigger.appendHandlerBody(java.lang.StringBuilder, java.util.List<java.lang.Object>)appear at$2+. The base implementation is empty.- Overrides:
appendInstallPreludein classDomEventTrigger- Parameters:
prelude- the prelude buffer; statements appended here run before the wrapper is created and remain in scope inside it
-
appendHandlerBody
Description copied from class:DomEventTriggerHook for subclasses to contribute statements to the wrapper handler body and extra captures referenced by those statements. The base implementation appendse.preventDefault();ande.stopPropagation();when the corresponding flags are set.Subclasses overriding this method typically prepend their own guard statements (and call
super.appendHandlerBodyafterwards) so the guard runs beforepreventDefault— preventing the default action on events the guard would have rejected would be wrong. Each entry added toextraCapturesis appended after the event name capture, so the first extra is referenced as$2in the body, the next as$3, and so on.- Overrides:
appendHandlerBodyin classDomEventTrigger- Parameters:
body- the wrapper body so far; statements appended here run inside theconst h = e => { ... $0(e); }wrapper, in order, with the event available aseextraCaptures- mutable list of captures appended after the event-name capture ($1); the first capture added is$2, etc.
-