跳转到内容

Portal API

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

导入

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

Portals provide a first-class way to render children into a DOM node that exists outside the DOM hierarchy of the parent component.

属性

名称类型默认值描述
childrennode
The children to render into the container.
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.
disablePortalboolfalse
The children will be inside the DOM hierarchy of the parent component.

组件无法持有 ref。

演示项目