structyl

Click-Away Listener

stable

Calls a handler when interaction happens outside its child.

Basic usage

Examples

Dismiss a panel

Open a panel and click anywhere outside to close it. Clicks inside are ignored.

Tooltip-style popover

Use with a dropdown or popover surface — inside clicks keep it open.

onClickAway callback

Receives the raw mouse or touch event — use it to close, dismiss, or reset.

Features

  • Document-level mouse and touch support.
  • No visual wrapper.

Installation

bash
pnpm dlx structyl add click-away-listener

API Reference

ClickAwayListener

Outside interaction observer.

PropTypeDefault
onClickAway(event: MouseEvent | TouchEvent) => void

Called when the user interacts outside the child.

childrenReact.ReactNode

Observed child.

Click Away Listener | structyl