Skip to content

Commit 7f9517f

Browse files
authored
Merge pull request #4 from humanlayer/publish-humanlayer
feat: default useKey to true
2 parents 1994b7f + 51c4a67 commit 7f9517f

File tree

7 files changed

+23
-17
lines changed

7 files changed

+23
-17
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,6 @@ typings/
6868

6969
# next.js build output
7070
.next
71+
72+
# Riptide artifacts (cloud-synced)
73+
.humanlayer/tasks/

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@humanlayer/react-hotkeys-hook",
33
"description": "React hook for handling keyboard shortcuts (HumanLayer fork)",
4-
"version": "5.2.6",
4+
"version": "5.3.0",
55
"sideEffects": false,
66
"repository": {
77
"type": "git",

packages/react-hotkeys-hook/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-hotkeys-hook",
3-
"version": "5.2.6",
3+
"version": "5.3.0",
44
"type": "module",
55
"scripts": {
66
"dev": "vite",

packages/react-hotkeys-hook/src/lib/parseHotkeys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function parseHotkey(
3737
hotkey: string,
3838
splitKey = '+',
3939
sequenceSplitKey = '>',
40-
useKey = false,
40+
useKey = true,
4141
description?: string,
4242
metadata?: Record<string, unknown>,
4343
): Hotkey {

packages/react-hotkeys-hook/src/lib/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export type Options = {
8181
ignoreModifiers?: boolean
8282
// Pass through event listener options. (Default: undefined)
8383
eventListenerOptions?: EventListenerOptions
84-
// Listen to the produced key instead of the code. (Default: false)
84+
// Listen to the produced key instead of the code. (Default: true)
8585
useKey?: boolean
8686
// The timeout to wait for the next key to be pressed. (Default: 1000ms)
8787
sequenceTimeoutMs?: number

packages/react-hotkeys-hook/src/lib/validators.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ export const isHotkeyMatchingKeyboardEvent = (e: KeyboardEvent, hotkey: Hotkey,
127127
// If useKey is set, match against the produced key value instead of the key code
128128
// When useKey is true, we ONLY match produced keys — never fall through to code-based matching
129129
if (useKey) {
130+
// Normalize produced key: map ' ' to 'space' so hotkey string 'space' works with useKey
131+
const normalizedKey = producedKey === ' ' ? 'space' : producedKey.toLowerCase()
130132
if (keys?.length === 1) {
131-
return keys.includes(producedKey.toLowerCase())
133+
return keys.includes(normalizedKey)
132134
}
133135
if (keys && keys.length > 0) {
134136
return isHotkeyPressed(keys.map((k) => k.toLowerCase()))

packages/react-hotkeys-hook/src/test/useHotkeys.test.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ test('should listen to multiple combinations with modifiers', async () => {
376376
alt: true,
377377
meta: false,
378378
mod: false,
379-
useKey: false,
379+
useKey: true,
380380
isSequence: false,
381381
hotkey: 'alt+b',
382382
})
@@ -1055,7 +1055,8 @@ test('should listen to function keys f1-f16', async () => {
10551055
const user = userEvent.setup()
10561056
const callback = vi.fn()
10571057

1058-
renderHook(() => useHotkeys('f1, f16', callback))
1058+
// Function keys are physical keys — use code-based matching
1059+
renderHook(() => useHotkeys('f1, f16', callback, { useKey: false }))
10591060

10601061
await user.keyboard('[F1]')
10611062
await user.keyboard('[F16]')
@@ -1128,7 +1129,7 @@ test('should pass keyboard event and hotkey object to callback', async () => {
11281129
alt: false,
11291130
meta: false,
11301131
mod: false,
1131-
useKey: false,
1132+
useKey: true,
11321133
isSequence: false,
11331134
hotkey: 'a',
11341135
})
@@ -1150,7 +1151,7 @@ test('should set shift to true in hotkey object if listening to shift', async ()
11501151
alt: false,
11511152
meta: false,
11521153
mod: false,
1153-
useKey: false,
1154+
useKey: true,
11541155
isSequence: false,
11551156
hotkey: 'shift+a',
11561157
})
@@ -1172,7 +1173,7 @@ test('should set ctrl to true in hotkey object if listening to ctrl', async () =
11721173
alt: false,
11731174
meta: false,
11741175
mod: false,
1175-
useKey: false,
1176+
useKey: true,
11761177
isSequence: false,
11771178
hotkey: 'ctrl+a',
11781179
})
@@ -1194,7 +1195,7 @@ test('should set alt to true in hotkey object if listening to alt', async () =>
11941195
alt: true,
11951196
meta: false,
11961197
mod: false,
1197-
useKey: false,
1198+
useKey: true,
11981199
isSequence: false,
11991200
hotkey: 'alt+a',
12001201
})
@@ -1216,7 +1217,7 @@ test('should set mod to true in hotkey object if listening to mod', async () =>
12161217
alt: false,
12171218
meta: false,
12181219
mod: true,
1219-
useKey: false,
1220+
useKey: true,
12201221
isSequence: false,
12211222
hotkey: 'mod+a',
12221223
})
@@ -1238,7 +1239,7 @@ test('should set meta to true in hotkey object if listening to meta', async () =
12381239
alt: false,
12391240
meta: true,
12401241
mod: false,
1241-
useKey: false,
1242+
useKey: true,
12421243
isSequence: false,
12431244
hotkey: 'meta+a',
12441245
})
@@ -1260,7 +1261,7 @@ test('should set multiple modifiers to true in hotkey object if listening to mul
12601261
ctrl: false,
12611262
meta: false,
12621263
mod: true,
1263-
useKey: false,
1264+
useKey: true,
12641265
isSequence: false,
12651266
hotkey: 'mod+shift+a',
12661267
})
@@ -1362,7 +1363,7 @@ test('should call preventDefault option function with hotkey and keyboard event'
13621363
ctrl: false,
13631364
meta: false,
13641365
mod: false,
1365-
useKey: false,
1366+
useKey: true,
13661367
isSequence: false,
13671368
hotkey: 'a',
13681369
})
@@ -1597,11 +1598,11 @@ test('Should listen to produced key and not to code', async () => {
15971598
expect(callback).toHaveBeenCalledTimes(1)
15981599
})
15991600

1600-
test('Should not check produced key if useKey is not set', async () => {
1601+
test('Should not check produced key if useKey is false', async () => {
16011602
const user = userEvent.setup()
16021603
const callback = vi.fn()
16031604

1604-
renderHook(() => useHotkeys(`=`, callback))
1605+
renderHook(() => useHotkeys(`=`, callback, { useKey: false }))
16051606

16061607
await user.keyboard(`=`)
16071608

0 commit comments

Comments
 (0)