Class ShortcutTrigger

java.lang.Object
com.vaadin.flow.component.trigger.AbstractTrigger
com.vaadin.flow.component.trigger.ShortcutTrigger
All Implemented Interfaces:
Trigger, Serializable

public class ShortcutTrigger extends AbstractTrigger
Fires when the given key (with optional modifiers) is pressed while the host element is the active scope. The shortcut listens for keydown events that originate inside the host element, matching event.key against the configured Key and event.ctrlKey / altKey / shiftKey / metaKey against the configured KeyModifier set.

Bound actions run inside the keydown handler, preserving the user-gesture context.


 new ShortcutTrigger(form, Key.ENTER, KeyModifier.CONTROL)
         .triggers(new ClickAction(submitButton));
 
See Also:
  • Field Details

  • Constructor Details

    • ShortcutTrigger

      public ShortcutTrigger(Element host, Key key, KeyModifier... modifiers)
      Creates a shortcut trigger bound to the given host element.
      Parameters:
      host - the element acting as the shortcut's scope, not null
      key - the key to listen for, not null
      modifiers - modifier keys that must be held; empty for none
    • ShortcutTrigger

      public ShortcutTrigger(Component host, Key key, KeyModifier... modifiers)
      Creates a shortcut trigger bound to the given host component's root element.
      Parameters:
      host - the component acting as the shortcut's scope, not null
      key - the key to listen for, not null
      modifiers - modifier keys that must be held; empty for none
  • Method Details

    • getKey

      public Key getKey()
      Returns:
      the key this shortcut listens for
    • getModifiers

      public Set<KeyModifier> getModifiers()
      Returns:
      an unmodifiable view of the modifier set
    • buildClientConfig

      public tools.jackson.databind.node.ObjectNode buildClientConfig(ConfigContext context)
      Description copied from class: AbstractTrigger
      Produces the JSON configuration this trigger sends to the client. Default is an empty object; override to add type-specific options.

      The context lets subclasses encode element/output references by id when needed. Public so the internal framework can read the config without reflection; subclasses just override.

      Overrides:
      buildClientConfig in class AbstractTrigger
      Parameters:
      context - the resolver for referenced elements and outputs, not null
      Returns:
      a Jackson ObjectNode, never null