Skip to content

Commit

Permalink
[core] feat(useHotkeys): accept custom document for global handlers (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya authored Jun 22, 2021
1 parent 9a5c7b7 commit f752acc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/core/src/hooks/hotkeys/use-hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ and configure the <kbd>?</kbd> key to open the generated hotkeys dialog, but it
event handlers with the returned `handleKeyDown` and `handleKeyUp` functions. The hook takes an optional
second parameter which can customize some of its default behavior.

@interface UseHotkeysOptions

@method useHotkeys

@interface HotkeyConfig
10 changes: 9 additions & 1 deletion packages/core/src/hooks/hotkeys/useHotkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ import { HotkeysContext } from "../../context";
import { HotkeyConfig } from "./hotkeyConfig";

export interface UseHotkeysOptions {
/**
* A custom document to reference when binding global event handlers.
* This can be useful when using iframes in an application.
*
* @default window.document
*/
document?: Document;

/**
* The key combo which will trigger the hotkeys dialog to open.
*
Expand All @@ -41,7 +49,7 @@ export interface UseHotkeysReturnValue {
* @param options hook options
*/
export function useHotkeys(keys: HotkeyConfig[], options: UseHotkeysOptions = {}): UseHotkeysReturnValue {
const { showDialogKeyCombo = "?" } = options;
const { document = window.document, showDialogKeyCombo = "?" } = options;
const localKeys = React.useMemo(
() =>
keys
Expand Down

1 comment on commit f752acc

@blueprint-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[core] feat(useHotkeys): accept custom document for global handlers (#4773)

Previews: documentation | landing | table

Please sign in to comment.