Modal API
The API documentation of the Modal React component. Learn more about the props and the CSS customization points.
Import
import Modal from '@material-ui/core/Modal';
// or
import { Modal } from '@material-ui/core';
You can learn more about the difference by reading this guide.
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.
Props
Name | Type | Default | Description |
---|---|---|---|
BackdropComponent | elementType | SimpleBackdrop | A backdrop component. This prop enables custom backdrop rendering. |
BackdropProps | object | Props applied to the Backdrop element. |
|
children* | element | A single child content element. ⚠️ Needs to be able to hold a ref. |
|
closeAfterTransition | bool | false | When set to true the Modal waits until a nested Transition is completed before closing. |
container | HTML element | React.Component | func |
A HTML element, component instance, or function that returns either. 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. |
|
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 the disableAutoFocus prop.Generally this should never be set to true as it makes the modal less accessible to assistive technologies, like screen readers. |
bool | false | Deprecated. Use the onClose prop with the reason argument to filter the backdropClick events.If true , clicking the backdrop will not fire onClose . |
|
disableEnforceFocus | bool | false | If true , the modal will not prevent focus from leaving the modal while open.Generally this should never be set to true as it makes the modal less accessible to assistive technologies, like screen readers. |
disableEscapeKeyDown | bool | false | If true , hitting escape will not fire onClose . |
disablePortal | bool | false | Disable the portal behavior. The children stay within it's parent DOM hierarchy. |
disableRestoreFocus | bool | false | If true , the modal will not restore focus to previously focused element once modal is hidden. |
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. |
func | Deprecated. Use the onClose prop with the reason argument to handle the backdropClick events.Callback fired when the backdrop is clicked. |
||
onClose | func | Callback fired when the component requests to be closed. The reason parameter can optionally be used to control the response to onClose .Signature: function(event: object, reason: string) => void event: The event source of the callback. reason: Can be: "escapeKeyDown" , "backdropClick" . |
|
func | Deprecated. Use the onClose prop with the reason argument to handle the escapeKeyDown events.Callback fired when the escape key is pressed, disableEscapeKeyDown is false and the modal is in focus. |
||
func | Deprecated. Use the ref instead. Callback fired once the children has been mounted into the container . It signals that the open={true} prop took effect.This prop will be removed in v5, the ref can be used instead. |
||
open* | bool | If true , the modal is open. |
The ref
is forwarded to the root element.
Any other props supplied will be provided to the root element (native element).