Modal API
导入
import Modal from '@mui/material/Modal';
// 或
import { Modal } from '@mui/material';Modal is a lower-level construct that is leveraged by the following components:
If you are creating a modal dialog, you probably want to use the Dialog component rather than directly using Modal.
This component shares many concepts with react-overlays.
组件名称
在主题中,名称“MuiModal”可用于提供默认属性(props),或者样式覆盖属性
原生(Native) 组件的属性也是可用的。
| 名称 | 类型 | 默认值 | 描述 | 
|---|---|---|---|
| children* | element | A single child content element. ⚠️ Needs to be able to hold a ref. | |
| open* | bool | false | Control the popup` open state. | 
| BackdropComponent | elementType | styled(Backdrop, { name: 'MuiModal', slot: 'Backdrop', overridesResolver: (props, styles) => { return styles.backdrop; }, })({ zIndex: -1, }) | A backdrop component. This prop enables custom backdrop rendering. | 
| BackdropProps | object | Props applied to the  Backdropelement. | |
| classes | object | Override or extend the styles applied to the component. See CSS API below for more details. | |
| closeAfterTransition | bool | false | When set to true the Modal waits until a nested Transition is completed before closing. | 
| component | elementType | The component used for the root node. Either a string to use a HTML element or a component. | |
| components | { Backdrop?: elementType, Root?: elementType } | {} | The components used for each slot inside the Modal. Either a string to use a HTML element or a component. | 
| componentsProps | { backdrop?: func | object, root?: func | object } | {} | The props used for each slot inside the Modal. | 
| container | HTML element | func | A HTML element or function that returns one. The  containerwill have the portal children appended to it.By default, it uses the body of the top-level document object, so it's simply document.bodymost of the time. | |
| disableAutoFocus | bool | false | If  true, the modal will not automatically shift focus to itself when it opens, and replace it to the last focused element when it closes. This also works correctly with any modal children that have thedisableAutoFocusprop.Generally this should never be set to trueas it makes the modal less accessible to assistive technologies, like screen readers. | 
| disableEnforceFocus | bool | false | If  true, the modal will not prevent focus from leaving the modal while open.Generally this should never be set to trueas it makes the modal less accessible to assistive technologies, like screen readers. | 
| disableEscapeKeyDown | bool | false | If  true, hitting escape will not fire theonClosecallback. | 
| disablePortal | bool | false | The  childrenwill be inside the DOM hierarchy of the parent component. | 
| disableRestoreFocus | bool | false | If  true, the modal will not restore focus to previously focused element once modal is hidden or unmounted. | 
| disableScrollLock | bool | false | Disable the scroll lock behavior. | 
| hideBackdrop | bool | false | If  true, the backdrop is not rendered. | 
| keepMounted | bool | false | 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 Modal. | 
| onBackdropClick | func | Callback fired when the backdrop is clicked. | |
| onClose | func | Callback fired when the component requests to be closed. The  reasonparameter can optionally be used to control the response toonClose.Signature: function(event: object, reason: string) => voidevent: The event source of the callback. reason: Can be: "escapeKeyDown","backdropClick". | |
| slotProps | { backdrop?: func | object, root?: func | object } | {} | |
| slots | { backdrop?: elementType, root?: elementType } | {} | |
| sx | Array<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. | 
ref 则会被传递到根元素中。CSS
| 规则名称 | 全局类名 | 描述 | 
|---|---|---|
| root | .MuiModal-root | Styles applied to the root element. | 
| hidden | .MuiModal-hidden | Styles applied to the root element if the Modalhas exited. | 
您可以使用组件自定义选项对组件进行个性化:
- 具备 全局类名.
- 在自定义主体中,设定一个规则名称作为组件的styleOverrides属性的一部分。