Skip to content

Commit

Permalink
Fix trouble combining keyup event, key name and modificator "once"
Browse files Browse the repository at this point in the history
  • Loading branch information
lozunoff committed Mar 5, 2022
1 parent ca6ae29 commit 88691ed
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/alpinejs/src/utils/on.js
Expand Up @@ -38,6 +38,14 @@ export default function on (el, event, modifiers, callback) {
})
}

if (modifiers.includes('once')) {
handler = wrapHandler(handler, (next, e) => {
next(e)

listenerTarget.removeEventListener(event, handler, options)
})
}

// Handle :keydown and :keyup listeners.
handler = wrapHandler(handler, (next, e) => {
if (isKeyEvent(event)) {
Expand All @@ -63,14 +71,6 @@ export default function on (el, event, modifiers, callback) {
handler = throttle(handler, wait)
}

if (modifiers.includes('once')) {
handler = wrapHandler(handler, (next, e) => {
next(e)

listenerTarget.removeEventListener(event, handler, options)
})
}

listenerTarget.addEventListener(event, handler, options)

return () => {
Expand Down

0 comments on commit 88691ed

Please sign in to comment.