OutsideClickDetector

Primitive #11

🔍 Problem it solves

Dropdowns, popovers, and select menus should close when the user clicks anywhere outside them. But you must ignore clicks on the trigger element itself and respect portal boundaries.

✅ Solution

Detects clicks outside a given element using event delegation. Ignores clicks on a specified trigger element and works even when the overlay is rendered in a portal.

🧩 Used by components

Dropdown, Popover, Select, Combobox, ContextMenu, Tooltip, DatePicker

🎮 Interactive demo