跳转到内容

ClickAwayListener API

想要学习更多组件属性和 CSS API,可以查阅 React ClickAwayListener 组件的 API 文档。

导入

import ClickAwayListener from '@mui/base/ClickAwayListener';
// 或
import { ClickAwayListener } from '@mui/base';
你可以阅读这个关于最小化捆绑包的指南以了解以上二者的差异。

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.

属性

名称类型默认值描述
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.

组件无法持有 ref。

演示项目