Skip to content

Commit

Permalink
fix(useMagicKeys): reset refs on target blur (#1755)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
lavolpecheprogramma and antfu committed Jul 6, 2022
1 parent 4c37839 commit 82510b8
Showing 1 changed file with 13 additions and 0 deletions.
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

0 comments on commit 82510b8

Please sign in to comment.