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

feat(useFocusTrap): new function #433

Merged
merged 8 commits into from Apr 8, 2021
2 changes: 1 addition & 1 deletion packages/integrations/useFocusTrap/demo.vue
Expand Up @@ -9,7 +9,7 @@ const { hasFocus, activate, deactivate } = useFocusTrap(target)
<template>
<div class="flex flex-col items-center">
<button @click="activate()">
Trap Focus
Trap Focus Within Form
</button>
<input
type="text"
Expand Down
8 changes: 4 additions & 4 deletions packages/integrations/useFocusTrap/index.ts
Expand Up @@ -86,9 +86,6 @@ export function useFocusTrap(target: MaybeElementRef, options: UseFocusTrapOptio
const stop = watch(
() => unrefElement(target),
(el: HTMLElement) => {
if (el)
stop()

trap = createFocusTrap(el, {
...focusTrapOptions,
onActivate() {
Expand All @@ -113,7 +110,10 @@ export function useFocusTrap(target: MaybeElementRef, options: UseFocusTrapOptio
}, { flush: 'post' })

// Cleanup on unmount
tryOnUnmounted(deactivate)
tryOnUnmounted(() => {
stop()
wheatjs marked this conversation as resolved.
Show resolved Hide resolved
deactivate()
})

return {
hasFocus,
Expand Down