v3-click-outside

Vue3 directive to react on clicks outside an element. Its simple to use. And can Customizable boundary elements.
22,256 4
Install
npm install v3-click-outside
Latest Version:1.1.0
License:MIT
Last Updated:Aug 19, 2022
Links: GitHub  ·  npm
Maintainer: onedayday

v3-click-outside

English | 中文

Vue3 directive to react on clicks outside an element. It is simple to use. And can Customizable boundary elements.

Install

npm install --save v3-click-outside

Use

import { createApp } from 'vue'
import App from './App.vue'
import clickOutside from 'v3-click-outside'

const app = createApp(App)
app.use(clickOutside)
1. If boundary element is the document.

just pass a function to the directive. The function will accept two parameters: one is a boolean which indicates whether the click is outside the element, the other is the event object.

<template>
  <div v-click-outside="handleClickOustside"></div>
</template>

<script setup>
  //the function accept a booleam parameter, true indicate click outside
  const handleClickOustside = (isOutside, e) => {
    if (isOutside) //do something
    else //do something else
  }
</script>
2. you can also define the boundary element that you want.

In this case, you need to pass an array which has two parameters. One is a function like above, and another is a CSS selector or a DOM element as the boundary element. The order of the arguments does not matter.

<template>
  <div class="outer">
    <div class="inner" v-click-outside="[handleClickOustside, '.outer']"></div>
  </div>
</template>

<script setup>
  //the function accept a booleam parameter, true indicate click outside
  const handleClickOustside = (isOutside, e) => {
    if (isOutside) //do something
    else //do something else
  }
</script>

License

MIT

Related Packages

v-click-outside-x

Vue directive to react on clicks outside an element.

792,715 7
vue-clickoutside

A Vue directive about listener a click outside an element.

9,169 10
vue-outside-click

Directive for VueJS, handle click outside target element

5,228 1
vue-click-outside-of

Vue 3 directive and hook for detecting click outside an element

18,967 1
vue-click-helper

A Vue directive to distinguish between click and double click

3,059 10

Version History

Version Released License
1.1.0 MIT
1.0.10 MIT
1.0.9 MIT
1.0.8 MIT
1.0.7 MIT