react-hotkeys-hook 4.4.2 → 4.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ import { FormTags, Hotkey, Scopes, Trigger } from './types';
2
+ export declare function maybePreventDefault(e: KeyboardEvent, hotkey: Hotkey, preventDefault?: Trigger): void;
3
+ export declare function isHotkeyEnabled(e: KeyboardEvent, hotkey: Hotkey, enabled?: Trigger): boolean;
4
+ export declare function isKeyboardEventTriggeredByInput(ev: KeyboardEvent): boolean;
5
+ export declare function isHotkeyEnabledOnTag({ target }: KeyboardEvent, enabledOnTags?: readonly FormTags[] | boolean): boolean;
6
+ export declare function isScopeActive(activeScopes: string[], scopes?: Scopes): boolean;
7
+ export declare const isHotkeyMatchingKeyboardEvent: (e: KeyboardEvent, hotkey: Hotkey, ignoreModifiers?: boolean) => boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-hotkeys-hook",
3
3
  "description": "React hook for handling keyboard shortcuts",
4
- "version": "4.4.2",
4
+ "version": "4.4.3",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/JohannesKlauss/react-keymap-hook.git"
@@ -78,18 +78,18 @@
78
78
  }
79
79
  },
80
80
  "devDependencies": {
81
- "@babel/core": "7.23.2",
81
+ "@babel/core": "7.23.7",
82
82
  "@babel/plugin-proposal-class-properties": "7.18.6",
83
- "@babel/plugin-transform-react-jsx": "7.22.15",
84
- "@babel/preset-env": "7.23.2",
85
- "@babel/preset-react": "7.22.15",
86
- "@babel/preset-typescript": "7.23.2",
83
+ "@babel/plugin-transform-react-jsx": "7.23.4",
84
+ "@babel/preset-env": "7.23.7",
85
+ "@babel/preset-react": "7.23.3",
86
+ "@babel/preset-typescript": "7.23.3",
87
87
  "@testing-library/jest-dom": "5.17.0",
88
- "@testing-library/react": "14.0.0",
89
- "@testing-library/user-event": "14.4.3",
90
- "@types/jest": "29.5.6",
91
- "@types/react": "18.2.33",
92
- "@types/react-dom": "18.2.14",
88
+ "@testing-library/react": "14.1.2",
89
+ "@testing-library/user-event": "14.5.2",
90
+ "@types/jest": "29.5.11",
91
+ "@types/react": "18.2.46",
92
+ "@types/react-dom": "18.2.18",
93
93
  "@typescript-eslint/eslint-plugin": "5.60.0",
94
94
  "@typescript-eslint/parser": "5.60.0",
95
95
  "eslint": "8.56.0",
@@ -102,8 +102,8 @@
102
102
  "react-dom": "18.2.0",
103
103
  "react-test-renderer": "18.2.0",
104
104
  "tsdx": "0.14.1",
105
- "tslib": "2.5.3",
106
- "typescript": "5.0.4"
105
+ "tslib": "2.6.2",
106
+ "typescript": "5.3.3"
107
107
  },
108
108
  "peerDependencies": {
109
109
  "react": ">=16.8.1",
package/src/useHotkeys.ts CHANGED
@@ -64,20 +64,18 @@ export default function useHotkeys<T extends HTMLElement>(
64
64
  return
65
65
  }
66
66
 
67
- if (memoisedOptions?.ignoreEventWhen?.(e)) {
68
- return
69
- }
70
-
71
67
  // TODO: SINCE THE EVENT IS NOW ATTACHED TO THE REF, THE ACTIVE ELEMENT CAN NEVER BE INSIDE THE REF. THE HOTKEY ONLY TRIGGERS IF THE
72
68
  // REF IS THE ACTIVE ELEMENT. THIS IS A PROBLEM SINCE FOCUSED SUB COMPONENTS WON'T TRIGGER THE HOTKEY.
73
- if (
74
- ref.current !== null &&
75
- document.activeElement !== ref.current &&
76
- !ref.current.contains(document.activeElement)
77
- ) {
78
- stopPropagation(e)
79
-
80
- return
69
+ if (ref.current !== null) {
70
+ const rootNode = ref.current.getRootNode()
71
+ if (
72
+ (rootNode instanceof Document || rootNode instanceof ShadowRoot) &&
73
+ rootNode.activeElement !== ref.current &&
74
+ !ref.current.contains(rootNode.activeElement)
75
+ ) {
76
+ stopPropagation(e)
77
+ return
78
+ }
81
79
  }
82
80
 
83
81
  if ((e.target as HTMLElement)?.isContentEditable && !memoisedOptions?.enableOnContentEditable) {
@@ -88,6 +86,10 @@ export default function useHotkeys<T extends HTMLElement>(
88
86
  const hotkey = parseHotkey(key, memoisedOptions?.combinationKey)
89
87
 
90
88
  if (isHotkeyMatchingKeyboardEvent(e, hotkey, memoisedOptions?.ignoreModifiers) || hotkey.keys?.includes('*')) {
89
+ if (memoisedOptions?.ignoreEventWhen?.(e)) {
90
+ return
91
+ }
92
+
91
93
  if (isKeyUp && hasTriggeredRef.current) {
92
94
  return
93
95
  }
package/src/validators.ts CHANGED
@@ -59,7 +59,7 @@ export const isHotkeyMatchingKeyboardEvent = (e: KeyboardEvent, hotkey: Hotkey,
59
59
  const pressedKey = pressedKeyUppercase.toLowerCase()
60
60
 
61
61
  if (!keys?.includes(keyCode) && !['ctrl', 'control', 'unknown', 'meta', 'alt', 'shift', 'os'].includes(keyCode)) {
62
- return false;
62
+ return false
63
63
  }
64
64
 
65
65
  if (!ignoreModifiers) {