跳转到内容

Popper API

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

导入

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

属性

原生(Native) 组件的属性也是可用的。

名称类型默认值描述
open*boolfalse
Control the popup` open state.
anchorElHTML element
| object
| func
A HTML element, virtualElement, or a function that returns either. It's used to set the position of the popper. The return value will passed as the reference object of the Popper instance.
childrennode
| func
Popper render function or node.
components{ Root?: elementType }
The components used for each slot inside the Popper. Either a string to use a HTML element or a component.
componentsProps{ root?: func
| object }
The props used for each slot inside the Popper.
containerHTML element
| func
A HTML element or function that returns one. The container will have the portal children appended to it.
By default, it uses the body of the top-level document object, so it's simply document.body most of the time.
direction'ltr'
| 'rtl'
'ltr'
Direction of the text.
disablePortalboolfalse
The children will be inside the DOM hierarchy of the parent component.
keepMountedboolfalse
Always keep the children in the DOM. This prop can be useful in SEO situation or when you want to maximize the responsiveness of the Popper.
modifiersArray<{ data?: object, effect?: func, enabled?: bool, fn?: func, name?: any, options?: object, phase?: 'afterMain'
| 'afterRead'
| 'afterWrite'
| 'beforeMain'
| 'beforeRead'
| 'beforeWrite'
| 'main'
| 'read'
| 'write', requires?: Array<string>, requiresIfExists?: Array<string> }>
Popper.js is based on a "plugin-like" architecture, most of its features are fully encapsulated "modifiers".
A modifier is a function that is called each time Popper.js needs to compute the position of the popper. For this reason, modifiers should be very performant to avoid bottlenecks. To learn how to create a modifier, read the modifiers documentation.
placement'auto-end'
| 'auto-start'
| 'auto'
| 'bottom-end'
| 'bottom-start'
| 'bottom'
| 'left-end'
| 'left-start'
| 'left'
| 'right-end'
| 'right-start'
| 'right'
| 'top-end'
| 'top-start'
| 'top'
'bottom'
Popper placement.
popperOptions{ modifiers?: array, onFirstUpdate?: func, placement?: 'auto-end'
| 'auto-start'
| 'auto'
| 'bottom-end'
| 'bottom-start'
| 'bottom'
| 'left-end'
| 'left-start'
| 'left'
| 'right-end'
| 'right-start'
| 'right'
| 'top-end'
| 'top-start'
| 'top', strategy?: 'absolute'
| 'fixed' }
{}
Options provided to the Popper.js instance.
popperRefref
A ref that points to the used popper instance.
slotProps{ root?: func
| object }
slots{ root?: elementType }
sxArray<func
| object
| bool>
| func
| object
The system prop that allows defining system overrides as well as additional CSS styles. See the `sx` page for more details.
transitionboolfalse
Help supporting a react-transition-group/Transition component.

ref 则会被传递到根元素中。

演示项目