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): enable options in component #2321

Merged
merged 2 commits into from Oct 16, 2022
Merged
Show file tree
Hide file tree
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
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 @@ -64,7 +64,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