Skip to content

ClickAwayListener API

API reference docs for the React ClickAwayListener component. Learn about the props, CSS, and other APIs of this exported module.

Demos

For examples and details on the usage of this React component, visit the component demo pages:

Import

import ClickAwayListener from '@mui/base/ClickAwayListener';
// or
import { ClickAwayListener } from '@mui/base';
You can learn about the difference by reading this guide on minimizing bundle size.

Listen for click events that occur somewhere in the document, outside of the element itself. For instance, if you need to hide a menu when people click anywhere else on your page.

Props

NameTypeDefaultDescription
children*element
The wrapped element.
⚠️ Needs to be able to hold a ref.
onClickAway*func
Callback fired when a "click away" event is detected.
disableReactTreeboolfalse
If true, the React tree is ignored and only the DOM tree is considered. This prop changes how portaled elements are handled.
mouseEvent'onClick'
| 'onMouseDown'
| 'onMouseUp'
| 'onPointerDown'
| 'onPointerUp'
| false
'onClick'
The mouse event to listen to. You can disable the listener by providing false.
touchEvent'onTouchEnd'
| 'onTouchStart'
| false
'onTouchEnd'
The touch event to listen to. You can disable the listener by providing false.

The component cannot hold a ref.