Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(useMagicKeys): reset refs on target blur #1755

Merged
merged 3 commits into from Jul 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/core/useMagicKeys/index.ts
Expand Up @@ -94,6 +94,15 @@ export function useMagicKeys(options: UseMagicKeysOptions<boolean> = {}): any {
}
}

function reset() {
for (const key of Object.keys(refs)) {
if (useReactive)
refs[key] = false
else
refs[key].value = false
}
}

function updateRefs(e: KeyboardEvent, value: boolean) {
const key = e.key?.toLowerCase()
const code = e.code?.toLowerCase()
Expand Down Expand Up @@ -135,6 +144,10 @@ export function useMagicKeys(options: UseMagicKeysOptions<boolean> = {}): any {
updateRefs(e, false)
return onEventFired(e)
}, { passive })

// #1350
useEventListener('blur', reset, { passive: true })
useEventListener('focus', reset, { passive: true })
}

const proxy = new Proxy(
Expand Down