useClickOutsideui-interaction
useClickOutside
NewSSR SAFEDetects clicks outside of a target element.
$ pnpm dlx shadcn@latest add @byphongphan/use-click-outsideRequires
@byphongphan in components.jsonuse-click-outside.tsx
Loading preview...
Installation
$ pnpm dlx shadcn@latest add @byphongphan/use-click-outsideRequires
@byphongphan in components.jsonUsage
Props & Parameters
| Param | Type | Default | Description |
|---|---|---|---|
handler | (event: MouseEvent | TouchEvent) => void | — | Callback invoked when a click or touch event occurs outside the referenced element. |
options.enabled | boolean | true | Whether the click outside event listener is active. |
options.events | string[] | ["mousedown", "touchstart"] | Array of DOM event types to listen for. |
options.ignoreRefs | RefObject<HTMLElement>[] | [] | Optional list of other element refs whose clicks will not trigger the callback. |