@featherds/composables
Advanced tools
Comparing version 0.12.1 to 0.12.2
import { Ref } from "vue"; | ||
declare const useOutsideClick: (elementRef: Ref<HTMLElement> | Ref<HTMLElement[]>, listener: (e?: FocusEvent) => void) => Ref<boolean>; | ||
declare const useOutsideClick: (elementRef: Ref<HTMLElement> | Ref<HTMLElement[]>, listener: (e?: FocusEvent) => void, options?: { | ||
click?: boolean; | ||
focus?: boolean; | ||
window?: boolean; | ||
}) => Ref<boolean>; | ||
export { useOutsideClick }; |
import { watch, onBeforeUnmount, ref, onMounted } from "vue"; | ||
const useOutsideClick = (elementRef, listener) => { | ||
const useOutsideClick = (elementRef, listener, options = { | ||
click: true, | ||
focus: true, | ||
window: true, | ||
}) => { | ||
const active = ref(false); | ||
@@ -24,5 +28,11 @@ const windowBlurChecker = (e) => { | ||
if (document && window) { | ||
document.removeEventListener("click", outSideClick, true); | ||
document.removeEventListener("focus", outSideClick, true); | ||
window.removeEventListener("blur", windowBlurChecker); | ||
if (options.click) { | ||
document.removeEventListener("click", outSideClick, true); | ||
} | ||
if (options.focus) { | ||
document.removeEventListener("focus", outSideClick, true); | ||
} | ||
if (options.window) { | ||
window.removeEventListener("blur", windowBlurChecker); | ||
} | ||
} | ||
@@ -33,5 +43,11 @@ }; | ||
if (document && window && enabled) { | ||
document.addEventListener("click", outSideClick, true); | ||
document.addEventListener("focus", outSideClick, true); | ||
window.addEventListener("blur", windowBlurChecker); | ||
if (options.click) { | ||
document.addEventListener("click", outSideClick, true); | ||
} | ||
if (options.focus) { | ||
document.addEventListener("focus", outSideClick, true); | ||
} | ||
if (options.window) { | ||
window.addEventListener("blur", windowBlurChecker); | ||
} | ||
} | ||
@@ -38,0 +54,0 @@ else { |
@@ -5,3 +5,12 @@ import { watch, onBeforeUnmount, ref, onMounted, Ref } from "vue"; | ||
elementRef: Ref<HTMLElement> | Ref<HTMLElement[]>, | ||
listener: (e?: FocusEvent) => void | ||
listener: (e?: FocusEvent) => void, | ||
options: { | ||
click?: boolean; | ||
focus?: boolean; | ||
window?: boolean; | ||
} = { | ||
click: true, | ||
focus: true, | ||
window: true, | ||
} | ||
) => { | ||
@@ -30,5 +39,11 @@ const active = ref(false); | ||
if (document && window) { | ||
document.removeEventListener("click", outSideClick, true); | ||
document.removeEventListener("focus", outSideClick, true); | ||
window.removeEventListener("blur", windowBlurChecker); | ||
if (options.click) { | ||
document.removeEventListener("click", outSideClick, true); | ||
} | ||
if (options.focus) { | ||
document.removeEventListener("focus", outSideClick, true); | ||
} | ||
if (options.window) { | ||
window.removeEventListener("blur", windowBlurChecker); | ||
} | ||
} | ||
@@ -41,5 +56,11 @@ }; | ||
if (document && window && enabled) { | ||
document.addEventListener("click", outSideClick, true); | ||
document.addEventListener("focus", outSideClick, true); | ||
window.addEventListener("blur", windowBlurChecker); | ||
if (options.click) { | ||
document.addEventListener("click", outSideClick, true); | ||
} | ||
if (options.focus) { | ||
document.addEventListener("focus", outSideClick, true); | ||
} | ||
if (options.window) { | ||
window.addEventListener("blur", windowBlurChecker); | ||
} | ||
} else { | ||
@@ -46,0 +67,0 @@ removeEvents(); |
{ | ||
"name": "@featherds/composables", | ||
"version": "0.12.1", | ||
"version": "0.12.2", | ||
"publishConfig": { | ||
@@ -12,3 +12,3 @@ "access": "public" | ||
"dependencies": { | ||
"@featherds/utils": "^0.12.1", | ||
"@featherds/utils": "^0.12.2", | ||
"vue": "^3.1.0-0" | ||
@@ -20,3 +20,3 @@ }, | ||
], | ||
"gitHead": "72004491146456809a415fcb4959cb4288ac1d3d" | ||
"gitHead": "e7afa42afa38ecf89a0290f0ba8a1ddc22d67af2" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69526
1994
Updated@featherds/utils@^0.12.2