@bitrix24/b24ui-nuxt
Version:
Bitrix24 UI-Kit for developing web applications REST API for NUXT & VUE
16 lines (15 loc) • 496 B
JavaScript
import { watch, toValue } from "vue";
function blurActiveElement() {
if (!import.meta.client) return;
const active = document.activeElement;
if (active && active !== document.body) active.blur();
}
export function useBlurOnOpen(open, emits) {
watch(() => toValue(open), (val) => {
if (val) blurActiveElement();
}, { flush: "sync" });
return ((event, ...args) => {
if (event === "update:open" && args[0] === true) blurActiveElement();
return emits(event, ...args);
});
}