Skip to content

Commit

Permalink
feat(onClickOutside): support options in component (#2391)
Browse files Browse the repository at this point in the history
* fix(onClickOutside): missing options for component

It adds support for the options property when using onClickOutside via component

* docs: add example

Co-authored-by: sibbng <sibbngheid@gmail.com>
  • Loading branch information
fiadone and sibbng committed Nov 4, 2022
1 parent 3ddc754 commit c913b8f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions packages/core/onClickOutside/component.ts
@@ -1,16 +1,21 @@
import { defineComponent, h, ref } from 'vue-demi'
import { onClickOutside } from '@vueuse/core'
import type { RenderableComponent } from '../types'
import type { OnClickOutsideOptions } from '.'

export const OnClickOutside = defineComponent<RenderableComponent>({
export interface OnClickOutsideProps extends RenderableComponent {
options?: OnClickOutsideOptions
}

export const OnClickOutside = defineComponent<OnClickOutsideProps>({
name: 'OnClickOutside',
props: ['as'] as unknown as undefined,
props: ['as', 'options'] as unknown as undefined,
emits: ['trigger'],
setup(props, { slots, emit }) {
const target = ref()
onClickOutside(target, (e) => {
emit('trigger', e)
})
}, props.options)

return () => {
if (slots.default)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/onClickOutside/index.md
Expand Up @@ -39,7 +39,7 @@ export default {
## Component Usage

```html
<OnClickOutside @trigger="count++">
<OnClickOutside @trigger="count++" :options="{ ignore: [/* ... */] }">
<div>
Click Outside of Me
</div>
Expand Down

0 comments on commit c913b8f

Please sign in to comment.