On This Page

ClickOutsideListener

A utility component to detect click events outside of a wrapped component.

import { ClickOutsideListener } from '@deque/cauldron-react'

Example

<ClickOutsideListener onClickOutside={() => alert('You clicked outside!')}>
  <Button>Click Inside</Button>
</ClickOutsideListener>

Props

NameTypeDefaultDescription
children React.ReactNodeChild content.
onClickOutside
Required
MouseEvent | TouchEventCallback function for event type.
mouseEvent mousedown | click | mouseup | falseclickEvent type to listen to for mouse events.
touchEvent touchstart | touchend | falsetouchendEvent type to listen to for touch events.
target HTMLElement | React.RefObject | React.MutableRefObjectOptional element to attach events to if wrapped child does not have an accessible ref.