Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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