PXD

useOutsideClick

Detects clicks outside a container with allowlist support and optional enable/disable logic.

Exports

function useOutsideClick(
  container: MaybeElementRef<HTMLElement>,
  options?: Options,
): {
  stop: () => void
}

Types

interface Options {
  allowList?: MaybeElementRef<HTMLElement>[]
  enabled?: (ev: PointerEvent) => boolean
  onTrigger?: (ev: PointerEvent) => void
}

Params

NameTypeDescription
containerMaybeElementRef<HTMLElement>The container element to detect outside clicks for
options.allowListMaybeElementRef<HTMLElement>[]Elements excluded from outside click detection
options.enabled(ev: PointerEvent) => booleanWhether the outside click detection is enabled
options.onTrigger(ev: PointerEvent) => voidCallback fired when an outside click is detected

Source

Source