diff --git a/packages/theme/components/Header/SearchBar/SearchBar.vue b/packages/theme/components/Header/SearchBar/SearchBar.vue index fd590adc3..5cc7ea915 100644 --- a/packages/theme/components/Header/SearchBar/SearchBar.vue +++ b/packages/theme/components/Header/SearchBar/SearchBar.vue @@ -51,7 +51,7 @@ + + diff --git a/packages/theme/utilities/directives/click-outside/click-outside-directive.js b/packages/theme/utilities/directives/click-outside/click-outside-directive.js new file mode 100644 index 000000000..e8b839446 --- /dev/null +++ b/packages/theme/utilities/directives/click-outside/click-outside-directive.js @@ -0,0 +1,19 @@ +export const clickOutside = { + bind(el, binding) { + binding.name = "click-outside"; + const closeHandler = binding.value; + el._outsideClickHandler = function (event) { + if (!el.contains(event.target)) { + event.stopPropagation(); + closeHandler(event, el); + } + }; + document.addEventListener("mousedown", el._outsideClickHandler); + document.addEventListener("touchstart", el._outsideClickHandler); + }, + unbind(el) { + document.removeEventListener("mousedown", el._outsideClickHandler); + document.removeEventListener("touchstart", el._outsideClickHandler); + el._outsideClickHandler = null; + }, +};