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
| Name | Type | Default | Description |
|---|---|---|---|
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 |
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 | |
shouldIgnoreTarget? | (target: | ) => | isValueEntryTarget | Suppresses the shortcut when it returns |