com.vaadin.flow.component.
Class ShortcutRegistration
All Implemented Interfaces:
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.
bindLifecycleTo
(Component component) Binds the shortcut's life cycle to that of the given
Component
.Returns whether this listener will be called even in cases when the component is disabled.
getKey()
Get the primary
Key
of the shortcut.Component
which controls when the shortcut is active and when it is not.Get a set of
keys
where eachkey
is an instance of aKeyModifier
.getOwner()
Deprecated.
This component has now multiple owners so this method has been replaced by #getOwners().The
Component
s which own the shortcuts key event listeners.boolean
Checks if the default key behaviour in the browser is allowed by the shortcut.
boolean
Checks if the shortcut allows keydown event (associated with the shortcut) propagation in the browser.
boolean
Checks if shortcut resets focus on active element before triggering shortcut event handler.
boolean
Is the shortcut active on the current UI.
Fluently define the
Component
onto which the shortcut's listener is bound.void
remove()
Removes the
ShortcutRegistration
Reset focus on active element before triggering shortcut event handler.
void
setBrowserDefaultAllowed
(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.
void
setEventPropagationAllowed
(boolean eventPropagationAllowed) Set whether shortcut's keydown event is allowed to propagate up the DOM tree in the browser.
void
setResetFocusOnActiveElement
(boolean resetFocusOnActiveElement) Set if shortcut resets focus on active element before triggering shortcut event handler.
toString()
withAlt()
Fluently adds
KeyModifier.ALT
to the shortcut's modifiers.withCtrl()
Fluently adds
KeyModifier.CONTROL
to the shortcut's modifiers.withMeta()
Fluently adds
KeyModifier.META
to the shortcut's modifiers.withModifiers
(KeyModifier... keyModifiers) Configures
KeyModifiers
for the shortcut.Fluently adds
KeyModifier.SHIFT
to the shortcut's modifiers.
-
Method Details
-
withModifiers
Configures
KeyModifiers
for 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 adds
KeyModifier.ALT
to the shortcut's modifiers.Returns:
this
ShortcutRegistration
-
withCtrl
Fluently adds
KeyModifier.CONTROL
to the shortcut's modifiers.Returns:
this
ShortcutRegistration
-
withMeta
Fluently adds
KeyModifier.META
to the shortcut's modifiers.Returns:
this
ShortcutRegistration
-
withShift
Fluently adds
KeyModifier.SHIFT
to 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:
-
resetFocusOnActiveElement
Reset focus on active element before triggering shortcut event handler.
Returns:
this
ShortcutRegistration
See Also:
-
bindLifecycleTo
Binds the shortcut's life cycle to that of the given
Component
. When the givencomponent
is attached, the shortcut's listener is attached to theComponent
that owns the shortcut. When the givencomponent
is detached, so is the listener. is detached, the shortcut is removed from all attached scopes.Parameters:
component
- New lifecycle owner of the shortcutReturns:
this
ShortcutRegistration
-
listenOn
Fluently define the
Component
onto which the shortcut's listener is bound. Calling this method will remove the previous listener from thecomponent
it was bound to.Parameters:
listenOnComponents
-Component
s onto which the shortcut listeners are bound. Must not be null. Must not contain null. Must not have duplicate components.Returns:
this
ShortcutRegistration
-
remove
public void remove()Removes the
ShortcutRegistration
Removes all the underlying registrations tied to owner and lifecycle owner
components
.Specified by:
remove
in 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 primary
Key
of the shortcut. Primary key can be any key besides modifier keys.Returns:
Primary key
-
getModifiers
Get a set of
keys
where eachkey
is an instance of aKeyModifier
.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 is
false
.Returns:
Allows default key behavior
-
setBrowserDefaultAllowed
public void setBrowserDefaultAllowed(boolean browserDefaultAllowed) Set whether the default key behavior is allowed in the browser. The default value is
false
, and it prevents the default key events from taking place in the browser.Parameters:
browserDefaultAllowed
- Allow default behavior on keydown -
isEventPropagationAllowed
public boolean isEventPropagationAllowed()Checks if the shortcut allows keydown event (associated with the shortcut) propagation in the browser. The default value is
false
.Returns:
Allows event propagation
-
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 is
false
, and the DOM event is consumed by the shortcut handler.Parameters:
eventPropagationAllowed
- Allow event propagation -
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.
-
setResetFocusOnActiveElement
public void setResetFocusOnActiveElement(boolean resetFocusOnActiveElement) Set if shortcut resets focus on active element before triggering shortcut event handler. Reset means to first
blur()
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.activeElement
orshadowRoot.activeElement
if active element is theshadowRoot
.Parameters:
resetFocusOnActiveElement
- Reset focus on active element -
getOwner
Deprecated.This component has now multiple owners so this method has been replaced by #getOwners().Component
which owns the first shortcuts key event listener.Returns:
Component
-
getOwners
The
Component
s which own the shortcuts key event listeners.Returns:
Component[]
-
getLifecycleOwner
Component
which 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 to
DisabledUpdateMode.ONLY_WHEN_ENABLED
.Parameters:
disabledUpdateMode
-DisabledUpdateMode.ONLY_WHEN_ENABLED
to only fire events when the component is enabled,DisabledUpdateMode.ALWAYS
to fire events also when the component is disabled.Returns:
this registration, for chaining
-
getDisabledUpdateMode
Returns whether this listener will be called even in cases when the component is disabled.
Returns:
current disabledUpdateMode for this listener
-
toString
-