Merge pull request #5161 from dimaMachina/tsdoc2-7

Improve TSDoc comments for `type UseKeyPressOptions` and `useKeyPress` hook
This commit is contained in:
Moritz Klack
2025-04-06 20:59:59 +02:00
committed by GitHub
2 changed files with 25 additions and 8 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@xyflow/react': patch
---
Improve TSDoc comments for `type UseKeyPressOptions` and `useKeyPress` hook
+20 -8
View File
@@ -6,7 +6,15 @@ type PressedKeys = Set<string>;
type KeyOrCode = 'key' | 'code'; type KeyOrCode = 'key' | 'code';
export type UseKeyPressOptions = { export type UseKeyPressOptions = {
/**
* Listen to key presses on a specific element.
* @default document
*/
target?: Window | Document | HTMLElement | ShadowRoot | null; target?: Window | Document | HTMLElement | ShadowRoot | null;
/**
* You can use this flag to prevent triggering the key press hook when an input field is focused.
* @default true
*/
actInsideInputWithModifier?: boolean; actInsideInputWithModifier?: boolean;
preventDefault?: boolean; preventDefault?: boolean;
}; };
@@ -18,9 +26,7 @@ const defaultDoc = typeof document !== 'undefined' ? document : null;
* currently pressed or not. * currently pressed or not.
* *
* @public * @public
* @param param.keyCode - The key code (string or array of strings) to use * @param options - Options
* @param param.options - Options
* @returns boolean
* *
* @example * @example
* ```tsx * ```tsx
@@ -40,11 +46,17 @@ const defaultDoc = typeof document !== 'undefined' ? document : null;
*``` *```
*/ */
export function useKeyPress( export function useKeyPress(
/* /**
* the keycode can be a string 'a' or an array of strings ['a', 'a+d'] * The key code (string or array of strings) specifies which key(s) should trigger
* a string means a single key 'a' or a combination when '+' is used 'a+d' * an action.
* an array means different possibilites. Explainer: ['a', 'd+s'] here the *
* user can use the single key 'a' or the combination 'd' + 's' * A **string** can represent:
* - A **single key**, e.g. `'a'`
* - A **key combination**, using `'+'` to separate keys, e.g. `'a+d'`
*
* An **array of strings** represents **multiple possible key inputs**. For example, `['a', 'd+s']`
* means the user can press either the single key `'a'` or the combination of `'d'` and `'s'`.
* @default null
*/ */
keyCode: KeyCode | null = null, keyCode: KeyCode | null = null,
options: UseKeyPressOptions = { target: defaultDoc, actInsideInputWithModifier: true } options: UseKeyPressOptions = { target: defaultDoc, actInsideInputWithModifier: true }