react-hotkeys-hook 4.0.0-3 → 4.0.0-4
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.
- package/dist/index.js +3 -3
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
- package/src/parseHotkeys.ts +2 -1
- package/src/useHotkeys.ts +7 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-hotkeys-hook",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-4",
|
|
4
4
|
"repository": "https://JohannesKlauss@github.com/JohannesKlauss/react-keymap-hook.git",
|
|
5
5
|
"homepage": "https://johannesklauss.github.io/react-hotkeys-hook/",
|
|
6
6
|
"author": "Johannes Klauss",
|
package/src/parseHotkeys.ts
CHANGED
|
@@ -14,7 +14,8 @@ export function parseHotkey(hotkey: string, combinationKey: string = '+'): Hotke
|
|
|
14
14
|
const keys = hotkey
|
|
15
15
|
.toLocaleLowerCase()
|
|
16
16
|
.split(combinationKey)
|
|
17
|
-
.map(
|
|
17
|
+
.map(k => k.trim())
|
|
18
|
+
.map(k => k === 'esc' ? 'escape' : k)
|
|
18
19
|
|
|
19
20
|
const modifiers: KeyboardModifiers = {
|
|
20
21
|
alt: keys.includes('alt'),
|
package/src/useHotkeys.ts
CHANGED
|
@@ -47,7 +47,7 @@ export default function useHotkeys<T extends HTMLElement>(
|
|
|
47
47
|
return
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
// 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
|
|
50
|
+
// 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
|
|
51
51
|
// REF IS THE ACTIVE ELEMENT. THIS IS A PROBLEM SINCE FOCUSED SUB COMPONENTS WONT TRIGGER THE HOTKEY.
|
|
52
52
|
|
|
53
53
|
if (ref.current !== null && document.activeElement !== ref.current && !ref.current.contains(document.activeElement)) {
|
|
@@ -86,7 +86,12 @@ export default function useHotkeys<T extends HTMLElement>(
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
const handleKeyUp = (event: KeyboardEvent) => {
|
|
89
|
-
|
|
89
|
+
if (event.key.toLowerCase() !== 'meta') {
|
|
90
|
+
pressedDownKeys.delete(event.key.toLowerCase())
|
|
91
|
+
} else {
|
|
92
|
+
// On macOS pressing down the meta key prevents triggering the keyup event for any other key https://stackoverflow.com/a/57153300/735226.
|
|
93
|
+
pressedDownKeys.clear()
|
|
94
|
+
}
|
|
90
95
|
|
|
91
96
|
if (memoisedOptions?.keyup) {
|
|
92
97
|
listener(event)
|