UNPKG

@oruga-ui/oruga-next

Version:

UI components for Vue.js and CSS framework agnostic

34 lines (33 loc) 1.21 kB
"use strict"; /*! Oruga v0.11.0 | MIT License | github.com/oruga-ui/oruga */ require("vue"); const useEventListener = require("./useEventListener-CbsUbKWy.cjs"); const unrefElement = require("./unrefElement-BozOaxdL.cjs"); function useClickOutside(elements, handler, options) { if (!window) return () => { }; const listenerOptions = Object.assign({ ignore: [] }, options); const ignores = Array.isArray(elements) ? elements : [elements]; const shouldIgnore = (event) => { return ignores.some((target) => { if (typeof target === "string") { return Array.from( window.document.querySelectorAll(target) ).some( (el) => el === event.target || event.composedPath().includes(el) ); } else { const el = unrefElement.unrefElement(target); return el && (event.target === el || event.composedPath().includes(el)); } }); }; function listener(event) { if (shouldIgnore(event)) return; handler(event); } const stop = useEventListener.useEventListener(window, "click", listener, listenerOptions); return stop; } exports.useClickOutside = useClickOutside; //# sourceMappingURL=useClickOutside-CoQ2BNWF.cjs.map