MCPcopy Create free account
hub / github.com/bytebase/bytebase / useClickOutside

Function useClickOutside

frontend/src/react/components/ExprEditor.tsx:175–193  ·  view source on GitHub ↗
(
  refs: React.RefObject<HTMLElement | null>[],
  open: boolean,
  onClose: () => void
)

Source from the content-addressed store, hash-verified

173// ============================================================
174
175function useClickOutside(
176 refs: React.RefObject<HTMLElement | null>[],
177 open: boolean,
178 onClose: () => void
179) {
180 const refsRef = useRef(refs);
181 refsRef.current = refs;
182 useEffect(() => {
183 if (!open) return;
184 const handler = (e: MouseEvent) => {
185 const target = e.target as Node;
186 if (refsRef.current.every((r) => !r.current?.contains(target))) {
187 onClose();
188 }
189 };
190 document.addEventListener("mousedown", handler);
191 return () => document.removeEventListener("mousedown", handler);
192 }, [open, onClose]);
193}
194
195function PortaledDropdown({
196 anchorRef,

Callers 3

SearchableSelectFunction · 0.70
MultiSearchableSelectFunction · 0.70
MultiCheckSelectFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected