( refs: React.RefObject<HTMLElement | null>[], open: boolean, onClose: () => void )
| 173 | // ============================================================ |
| 174 | |
| 175 | function 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 | |
| 195 | function PortaledDropdown({ |
| 196 | anchorRef, |
no outgoing calls
no test coverage detected