Outside Click
Detect clicks outside a referenced element. Useful for closing dropdowns, popovers, and modals when the user clicks elsewhere.
Installation
dgadd is not public on npm yet. Until the first release, pack @diffgazer/add from the repository and install that tarball into this app, which is what puts dgadd on pnpm exec.
The hosted registry is not public yet because r.b4r7.dev does not resolve. Use this source checkout or a local registry preview until the endpoint returns 200.
Diffgazer packages are not yet published to npm. Until the first release, pack @diffgazer/ui and @diffgazer/keys from the repository and install those tarballs.
UI components require Tailwind CSS v4. Local copy mode imports src/styles/styles.css; package mode uses @diffgazer/ui CSS once packages are available.
Parameters
Returns
Examples
Dismiss Panel
Notes
Event Type
Uses capture-phase pointerdown when available, with capture-phase touchstart and mousedown fallbacks, to detect outside interactions before the click completes.
Conditional content
Pass the same open state as enabled when the referenced element mounts conditionally. The hook reconciles late ref attachment, node replacement, and owner-document changes after each commit.
Used By
Built into PopoverContent for dismiss-on-outside-click behavior.
Source
Highlighted source loads after this disclosure opens. Browse the source repository.
Event timing
The hook listens in the capture phase so dismissal runs before the later click. Modern documents use pointerdown; documents without Pointer Events install touchstart and mousedown fallbacks with the same capture-phase timing.
Overlay stack options
options is the fifth positional argument, after excludeRefs. Use priority when overlapping dismissal layers cannot be ordered by DOM nesting alone:
useOutsideClick reads priority from this shared options type. Its first ref and fourth excludeRefs arguments remain the outside-pointer and nested-overlay boundaries. useEscapeKey uses the options object's ref and excludeRefs fields because it has no separate boundary arguments.
Escape dismissal
The same source file also exports useEscapeKey for overlay dismissal stacks that need Escape handling without outside-pointer handling. Both hooks share the same priority and nested-overlay ordering options: