useOnClickOutside
Invokes a handler when a pointer, mouse, or touch interaction occurs outside one or more target elements (with Shadow DOM composedPath support).
Loading preview...
The useOnClickOutside hook detects clicks, taps, or pointer presses outside a target element (or an array of elements) using event.composedPath() for accurate Shadow DOM and portal handling.
Installation
Usage
Examples
Closing a Popover with a Separate Trigger Button
Pass an array of refs so clicking either the popover content or its trigger button does not count as an outside click.
Customizing the Event Type and Enabling Conditionally
Use eventType to listen on mouseup or click instead of pointerdown, and disable the listener when the overlay is closed.
API Reference
UseOnClickOutsideOptions
Configuration options for the outside interaction listener.
Property
Specification
enabled?uniondefault:true
Whether the outside click listener is active
Full Signature
events?arraydefault:['pointerdown']
DOM events to listen for on
documentFull Signature
capture?uniondefault:true
Listen during the capture phase
Full Signature