Skip to content

Commit fa0ce8b

Browse files
committed
add capslock as a modifer
1 parent 2fbb66f commit fa0ce8b

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export default function useHotkeys<T extends HTMLElement>(
140140
}
141141

142142
if (lastModiferKey) {
143-
if ((e as any)[`${lastModiferKey}Key`]) {
143+
if (lastModiferKey === 'capslock' || (e as any)[`${lastModiferKey}Key`]) {
144144
keysStack?.pop()
145145
lastKeyTime = performance.now()
146146
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,28 @@ test('should trigger sequence with modifier keys with useKey', async () => {
607607
expect(callback).toHaveBeenCalledTimes(1)
608608
})
609609

610+
test('should trigger sequence with capslock as modifer without useKey', async () => {
611+
const user = userEvent.setup({delay: 200})
612+
const callback = vi.fn()
613+
614+
renderHook(() => useHotkeys('1>2>3', callback, {useKey: false}))
615+
616+
await user.keyboard(`{CapsLock>}{1}{2}{3}`)
617+
618+
expect(callback).toHaveBeenCalledTimes(1)
619+
})
620+
621+
test('should trigger sequence with capslock as modifer with useKey', async () => {
622+
const user = userEvent.setup({delay: 200})
623+
const callback = vi.fn()
624+
625+
renderHook(() => useHotkeys('1>2>3', callback, { useKey: true }))
626+
627+
await user.keyboard(`{CapsLock>}{1}{2}{3}`)
628+
629+
expect(callback).toHaveBeenCalledTimes(1)
630+
})
631+
610632
test('should reflect set delimiter character', async () => {
611633
const user = userEvent.setup()
612634
const callback = vi.fn()

0 commit comments

Comments
 (0)