Skip to content

Commit

Permalink
feat(useFocusTrap): enable options in component (#2321)
Browse files Browse the repository at this point in the history
  • Loading branch information
azaleta committed Oct 16, 2022
1 parent a06b7bd commit 578bc0c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions packages/integrations/useFocusTrap/component.ts
Expand Up @@ -3,10 +3,15 @@ import { createFocusTrap } from 'focus-trap'
import type { FocusTrap } from 'focus-trap'
import type { RenderableComponent } from '@vueuse/core'
import { unrefElement } from '@vueuse/core'
import type { UseFocusTrapOptions } from '.'

export const UseFocusTrap = defineComponent<RenderableComponent>({
export interface ComponentUseFocusTrapOptions extends RenderableComponent {
options?: UseFocusTrapOptions
}

export const UseFocusTrap = defineComponent <ComponentUseFocusTrapOptions> ({
name: 'UseFocusTrap',
props: ['as'] as unknown as undefined,
props: ['as', 'options'] as unknown as undefined,
setup(props, { slots }) {
let trap: undefined | FocusTrap
const target = ref()
Expand All @@ -18,7 +23,7 @@ export const UseFocusTrap = defineComponent<RenderableComponent>({
(el) => {
if (!el)
return
trap = createFocusTrap(el, {})
trap = createFocusTrap(el, props.options || {})
activate()
}, { flush: 'post' })

Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/useFocusTrap/index.md
Expand Up @@ -70,7 +70,7 @@ const show = ref(false)
</script>

<template>
<UseFocusTrap v-if="show">
<UseFocusTrap v-if="show" :options="{ immediate: true }">
<div class="modal">...</div>
</UseFocusTrap>
</template>
Expand Down

0 comments on commit 578bc0c

Please sign in to comment.