Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b6947f7

Browse filesBrowse files
authored
fix(useMagicKeys): fix key order issue on first use (#4505)
1 parent d08eb2c commit b6947f7
Copy full SHA for b6947f7

File tree

Expand file treeCollapse file tree

2 files changed

+67
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+67
-1
lines changed
+66Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { beforeEach, describe, expect, it } from 'vitest'
2+
import { useMagicKeys } from '.'
3+
4+
describe('useMagicKeys', () => {
5+
let target: HTMLInputElement
6+
beforeEach(() => {
7+
target = document.createElement('input')
8+
})
9+
it('single key', async () => {
10+
const { A } = useMagicKeys({ target })
11+
12+
target.dispatchEvent(new KeyboardEvent('keydown', {
13+
key: 'A',
14+
}))
15+
16+
expect(A.value).toBe(true)
17+
})
18+
it('multiple keys', async () => {
19+
const { Ctrl_Shift_Period } = useMagicKeys({ target })
20+
expect(Ctrl_Shift_Period.value).toBe(false)
21+
22+
target.dispatchEvent(new KeyboardEvent('keydown', {
23+
key: 'control',
24+
ctrlKey: true,
25+
}))
26+
expect(Ctrl_Shift_Period.value).toBe(false)
27+
28+
target.dispatchEvent(new KeyboardEvent('keydown', {
29+
key: 'shift',
30+
ctrlKey: true,
31+
shiftKey: true,
32+
}))
33+
expect(Ctrl_Shift_Period.value).toBe(false)
34+
35+
target.dispatchEvent(new KeyboardEvent('keydown', {
36+
key: 'Period',
37+
ctrlKey: true,
38+
shiftKey: true,
39+
}))
40+
expect(Ctrl_Shift_Period.value).toBe(true)
41+
})
42+
it('multiple keys(in a different order)', async () => {
43+
const { Ctrl_Shift_Period } = useMagicKeys({ target })
44+
expect(Ctrl_Shift_Period.value).toBe(false)
45+
46+
target.dispatchEvent(new KeyboardEvent('keydown', {
47+
key: 'shift',
48+
shiftKey: true,
49+
}))
50+
expect(Ctrl_Shift_Period.value).toBe(false)
51+
52+
target.dispatchEvent(new KeyboardEvent('keydown', {
53+
key: 'control',
54+
ctrlKey: true,
55+
shiftKey: true,
56+
}))
57+
expect(Ctrl_Shift_Period.value).toBe(false)
58+
59+
target.dispatchEvent(new KeyboardEvent('keydown', {
60+
key: 'Period',
61+
ctrlKey: true,
62+
shiftKey: true,
63+
}))
64+
expect(Ctrl_Shift_Period.value).toBe(true)
65+
})
66+
})

‎packages/core/useMagicKeys/index.ts

Copy file name to clipboardExpand all lines: packages/core/useMagicKeys/index.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export function useMagicKeys(options: UseMagicKeysOptions<boolean> = {}): any {
165165
if (!(prop in refs)) {
166166
if (/[+_-]/.test(prop)) {
167167
const keys = prop.split(/[+_-]/g).map(i => i.trim())
168-
refs[prop] = computed(() => keys.every(key => toValue(proxy[key])))
168+
refs[prop] = computed(() => keys.map(key => toValue(proxy[key])).every(Boolean))
169169
}
170170
else {
171171
refs[prop] = ref(false)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.