UNPKG

@konstructio/ui

Version:

A set of reusable and customizable React components built for konstruct.io

33 lines (32 loc) 789 B
import { useRef as l, useEffect as c, useCallback as u } from "react"; import { useMultiSelectDropdown as i } from "../contexts/MultiSelectDropdown.hook.js"; const f = () => { const n = l(null), { onOpen: e } = i(); c(() => { const t = new AbortController(), a = (o) => { o.key === "Escape" && e(!1); }, r = (o) => { n.current?.contains(o.target) || e(!1); }; return document.addEventListener("keydown", a, { signal: t.signal }), document.addEventListener("mousedown", r, { signal: t.signal }), () => { t.abort(); }; }, [e, n]); const s = u( (t) => { t.target?.closest("[data-value]") || e(!0); }, [e] ); return { wrapperRef: n, handleOpen: s }; }; export { f as useMultiSelectDropdown };