UNPKG

@opensig/opendesign

Version:

40 lines (39 loc) 1 kB
import { ref, onMounted, toValue, watch, onUnmounted } from "vue"; import { isOverflown } from "../_utils/dom.mjs"; import { useResizeObserver } from "./use-resize-observer.mjs"; function useElementOverflown(elementRef) { const result = ref(false); const check = () => { result.value = isOverflown(toValue(elementRef) ?? void 0); }; onMounted(() => { const { observe, unobserve } = useResizeObserver(); const el = toValue(elementRef); if (el) { check(); observe(el, check); } const stopWatch = watch( () => toValue(elementRef), (_el, oldEl) => { if (oldEl) unobserve(oldEl, check); if (_el) { check(); observe(_el, check); } else { result.value = false; } }, { flush: "post" } ); onUnmounted(() => { stopWatch(); const _el = toValue(elementRef); if (_el) unobserve(_el, check); }); }); return result; } export { useElementOverflown };