Gathering detailed insights and metrics for click-outside-vue3
Gathering detailed insights and metrics for click-outside-vue3
Gathering detailed insights and metrics for click-outside-vue3
Gathering detailed insights and metrics for click-outside-vue3
🔲 Vue 3 directive to react on clicks outside an element without stopping the event propagation
npm install click-outside-vue3
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (85.03%)
Vue (12.45%)
HTML (2.52%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
79 Stars
397 Commits
8 Forks
4 Branches
1 Contributors
Updated on Jun 10, 2025
Latest Version
4.0.1
Package Id
click-outside-vue3@4.0.1
Unpacked Size
24.70 kB
Size
8.64 kB
File Count
20
NPM Version
6.14.8
Node Version
14.9.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Vue 3 directive to react on clicks outside an element without stopping the event propagation. Great for closing dialogues and menus among other things.
1$ npm install --save click-outside-vue3
1$ yarn add click-outside-vue3
1import { createApp } from "vue" 2import App from "./App.vue" 3import vClickOutside from "click-outside-vue3" 4 5const app = createApp(App) 6app.use(vClickOutside)
1<script> 2 export default { 3 data () { 4 vcoConfig: { 5 handler: this.handler, 6 middleware: this.middleware, 7 events: ['dblclick', 'click'], 8 // Note: The default value is true, but in case you want to activate / deactivate 9 // this directive dynamically use this attribute. 10 isActive: true, 11 // Note: The default value is true. See "Detecting Iframe Clicks" section 12 // to understand why this behaviour is behind a flag. 13 detectIFrame: true, 14 // Note: The default value is false. Sets the capture option for EventTarget addEventListener method. 15 // Could be useful if some event's handler calls stopPropagation method preventing event bubbling. 16 capture: false 17 } 18 }, 19 methods: { 20 onClickOutside (event) { 21 console.log('Clicked outside. Event: ', event) 22 }, 23 24 handler (event) { 25 console.log('Clicked outside (Using config), middleware returned true :)') 26 }, 27 // Note: The middleware will be executed if the event was fired outside the element. 28 // It should have only sync functionality and it should return a boolean to 29 // define if the handler should be fire or not 30 middleware (event) { 31 return event.target.className !== 'modal' 32 } 33 } 34 }; 35</script> 36 37<template> 38 <div v-click-outside="onClickOutside"></div> 39 <div v-click-outside="vcoConfig"></div> 40</template>
Or use it as a directive
1import vClickOutside from 'click-outside-vue3' 2 3<script> 4 export default { 5 directives: { 6 clickOutside: vClickOutside.directive 7 }, 8 methods: { 9 onClickOutside (event) { 10 console.log('Clicked outside. Event: ', event) 11 } 12 } 13 }; 14</script> 15 16<template> 17 <div v-click-outside="onClickOutside"></div> 18</template>
To our knowledge, there isn't an idiomatic way to detect a click on a <iframe>
(HTMLIFrameElement
).
Clicks on iframes moves focus
to its contents’ window
but don't bubble
up to main window
, therefore not triggering our document.documentElement
listeners. On the other hand, the abovementioned focus
event does trigger a window.blur
event on main window
that we use in conjunction with document.activeElement
to detect if it came from an <iframe>
, and execute the provided handler
.
As with any workaround, this also has its caveats:
iframe
via keyboard
navigation also triggers window.blur
consequently the handler - no workaround found ATM;Because of these reasons, the detection mechansim is behind the detectIframe
flag that you can optionally set to false
if you find it conflicting with your use-case.
Any improvements or suggestions to this are welcomed.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
112 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More