Skip to main content

useKeyboardShortcut

    The useKeyboardShortcut hook registers a keydown listener for a key combination in aria-keyshortcuts format and runs onTrigger when the user presses it. On top of that, the hook accepts mod, which resolves to Meta on macOS and to Control on every other platform.

    UseKeyboardShortcutOptions

    NameTypeDefaultDescription
    keys

    The combination that triggers the shortcut.

    onTrigger
    (event: ) =>

    Runs when the combination matches.

    eventTarget?
    | < | >
    document.body

    Where the listener is attached. A ref may still be null on the first render; the listener attaches once it resolves.

    enabled?
    true

    Whether the shortcut currently listens.

    preventDefault?
    true

    Whether the browser's default action for the combination is suppressed on a match.

    capture?
    false

    Whether the listener runs in the capture phase, ahead of descendants that call stopPropagation.

    shouldIgnoreTarget?
    (target: | ) =>
    isValueEntryTarget

    Suppresses the shortcut when it returns true for the event's target.

    Still have questions?
    Find answers in the Dynatrace Community