Package com.vaadin.flow.component
Class ShortcutRegistration
java.lang.Object
com.vaadin.flow.component.ShortcutRegistration
- All Implemented Interfaces:
Registration,Serializable
A registration object for both configuring and removing the registered
keyboard shortcut.
- Since:
- 1.3
- Author:
- Vaadin Ltd.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionAllows the default keyboard event handling when the shortcut is invoked.Allow the event to propagate upwards in the DOM tree, when the shortcut is invoked.Allow the shortcut to trigger for keyboard events that originate from a modal or popover nested inside the shortcut's listening scope.bindLifecycleTo(Component component) Binds the shortcut's life cycle to that of the givenComponent.Returns whether this listener will be called even in cases when the component is disabled.getKey()Get the primaryKeyof the shortcut.Componentwhich controls when the shortcut is active and when it is not.TheComponents which own the shortcuts key event listeners.booleanChecks if the default key behaviour in the browser is allowed by the shortcut.booleanChecks if the shortcut allows keydown event (associated with the shortcut) propagation in the browser.booleanChecks if the shortcut triggers for keyboard events originating from a modal or popover nested inside the shortcut's listening scope.booleanChecks if shortcut resets focus on active element before triggering shortcut event handler.booleanIs the shortcut active on the current UI.Fluently define theComponentonto which the shortcut's listener is bound.voidremove()Removes theShortcutRegistrationReset focus on active element before triggering shortcut event handler.voidsetBrowserDefaultAllowed(boolean browserDefaultAllowed) Set whether the default key behavior is allowed in the browser.setDisabledUpdateMode(DisabledUpdateMode disabledUpdateMode) Configure whether this listener will be called even in cases when the component is disabled.voidsetEventPropagationAllowed(boolean eventPropagationAllowed) Set whether shortcut's keydown event is allowed to propagate up the DOM tree in the browser.voidsetEventsFromNestedModalsAllowed(boolean eventsFromNestedModalsAllowed) Sets whether the shortcut triggers for keyboard events that originate from a modal or popover nested inside the shortcut's listening scope.voidsetResetFocusOnActiveElement(boolean resetFocusOnActiveElement) Set if shortcut resets focus on active element before triggering shortcut event handler.toString()withAlt()Fluently addsKeyModifier.ALTto the shortcut's modifiers.withCtrl()Fluently addsKeyModifier.CONTROLto the shortcut's modifiers.withMeta()Fluently addsKeyModifier.METAto the shortcut's modifiers.withModifiers(KeyModifier... keyModifiers) ConfiguresKeyModifiersfor the shortcut.Fluently addsKeyModifier.SHIFTto the shortcut's modifiers.
-
Method Details
-
withModifiers
ConfiguresKeyModifiersfor the shortcut. Calling this method will overwrite any previously set modifier keys. Hence, callingshortcutRegistration.withModifiers();will remove all previously set modifier keys.- Parameters:
keyModifiers- Key modifiers. Can be empty.- Returns:
- this
ShortcutRegistration
-
withAlt
Fluently addsKeyModifier.ALTto the shortcut's modifiers.- Returns:
- this
ShortcutRegistration
-
withCtrl
Fluently addsKeyModifier.CONTROLto the shortcut's modifiers.- Returns:
- this
ShortcutRegistration
-
withMeta
Fluently addsKeyModifier.METAto the shortcut's modifiers.- Returns:
- this
ShortcutRegistration
-
withShift
Fluently addsKeyModifier.SHIFTto the shortcut's modifiers.- Returns:
- this
ShortcutRegistration
-
allowBrowserDefault
Allows the default keyboard event handling when the shortcut is invoked.- Returns:
- this
ShortcutRegistration - See Also:
-
allowEventPropagation
Allow the event to propagate upwards in the DOM tree, when the shortcut is invoked.- Returns:
- this
ShortcutRegistration - See Also:
-
allowEventsFromNestedModals
Allow the shortcut to trigger for keyboard events that originate from a modal or popover nested inside the shortcut's listening scope.By default the shortcut does not trigger for such events. This restores behavior where a shortcut bound to a parent overlay would react to a keydown coming from a nested dialog/overlay that has focus.
- Returns:
- this
ShortcutRegistration - See Also:
-
resetFocusOnActiveElement
Reset focus on active element before triggering shortcut event handler.- Returns:
- this
ShortcutRegistration - Since:
- 24.3
- See Also:
-
bindLifecycleTo
Binds the shortcut's life cycle to that of the givenComponent. When the givencomponentis attached, the shortcut's listener is attached to theComponentthat owns the shortcut. When the givencomponentis detached, so is the listener. is detached, the shortcut is removed from all attached scopes.- Parameters:
component- New lifecycle owner of the shortcut- Returns:
- this
ShortcutRegistration
-
listenOn
Fluently define theComponentonto which the shortcut's listener is bound. Calling this method will remove the previous listener from thecomponentit was bound to.- Parameters:
listenOnComponents-Components onto which the shortcut listeners are bound. Must not be null. Must not contain null. Must not have duplicate components.- Returns:
- this
ShortcutRegistration - Since:
- 2.2
-
remove
public void remove()Removes theShortcutRegistrationRemoves all the underlying registrations tied to owner and lifecycle owner
components.- Specified by:
removein interfaceRegistration- See Also:
-
isShortcutActive
public boolean isShortcutActive()Is the shortcut active on the current UI. For this to be true, the lifecycle owner needs to be attached and visible and handler owner needs to be attached.- Returns:
- Is the shortcut active
-
getKey
Get the primaryKeyof the shortcut. Primary key can be any key besides modifier keys.- Returns:
- Primary key
-
getModifiers
- Returns:
- Set of modifier keys
-
isBrowserDefaultAllowed
public boolean isBrowserDefaultAllowed()Checks if the default key behaviour in the browser is allowed by the shortcut. The default value isfalse.- Returns:
- Allows default key behavior
- Since:
- 1.4
-
setBrowserDefaultAllowed
public void setBrowserDefaultAllowed(boolean browserDefaultAllowed) Set whether the default key behavior is allowed in the browser. The default value isfalse, and it prevents the default key events from taking place in the browser.- Parameters:
browserDefaultAllowed- Allow default behavior on keydown- Since:
- 1.4
-
isEventPropagationAllowed
public boolean isEventPropagationAllowed()Checks if the shortcut allows keydown event (associated with the shortcut) propagation in the browser. The default value isfalse.- Returns:
- Allows event propagation
- Since:
- 1.4
-
setEventPropagationAllowed
public void setEventPropagationAllowed(boolean eventPropagationAllowed) Set whether shortcut's keydown event is allowed to propagate up the DOM tree in the browser. The default value isfalse, and the DOM event is consumed by the shortcut handler.- Parameters:
eventPropagationAllowed- Allow event propagation- Since:
- 1.4
-
isEventsFromNestedModalsAllowed
public boolean isEventsFromNestedModalsAllowed()Checks if the shortcut triggers for keyboard events originating from a modal or popover nested inside the shortcut's listening scope. The default value isfalse.- Returns:
trueif events from nested modals are allowed to trigger the shortcut
-
setEventsFromNestedModalsAllowed
public void setEventsFromNestedModalsAllowed(boolean eventsFromNestedModalsAllowed) Sets whether the shortcut triggers for keyboard events that originate from a modal or popover nested inside the shortcut's listening scope. The default value isfalse, meaning a keydown coming from a nested dialog/overlay does not trigger a shortcut bound to a parent scope.- Parameters:
eventsFromNestedModalsAllowed-trueto allow events from nested modals to trigger the shortcut
-
isResetFocusOnActiveElement
public boolean isResetFocusOnActiveElement()Checks if shortcut resets focus on active element before triggering shortcut event handler.- Returns:
- True when focus is reset on the active element, false otherwise.
- Since:
- 24.3
-
setResetFocusOnActiveElement
public void setResetFocusOnActiveElement(boolean resetFocusOnActiveElement) Set if shortcut resets focus on active element before triggering shortcut event handler. Reset means to firstblur()and thenfocus()the element. If element is an input field with a ValueChangeMode.ON_CHANGE, then resetting focus ensures that value change event is triggered before shortcut event is handled. Active element isdocument.activeElementorshadowRoot.activeElementif active element is theshadowRoot.- Parameters:
resetFocusOnActiveElement- Reset focus on active element- Since:
- 24.3
-
getOwners
TheComponents which own the shortcuts key event listeners.- Returns:
- Component[]
- Since:
- 2.2
-
getLifecycleOwner
Componentwhich controls when the shortcut is active and when it is not.- Returns:
- Component
- See Also:
-
setDisabledUpdateMode
Configure whether this listener will be called even in cases when the component is disabled. Defaults toDisabledUpdateMode.ONLY_WHEN_ENABLED.- Parameters:
disabledUpdateMode-DisabledUpdateMode.ONLY_WHEN_ENABLEDto only fire events when the component is enabled,DisabledUpdateMode.ALWAYSto fire events also when the component is disabled.- Returns:
- this registration, for chaining
- Since:
- 24.7
-
getDisabledUpdateMode
Returns whether this listener will be called even in cases when the component is disabled.- Returns:
- current disabledUpdateMode for this listener
- Since:
- 24.7
-
toString
-