Saltar al contenido

Modal API

API documentation for the React Modal component. Learn about the available props, and the CSS API.

Import

import Modal from '@material-ui/core/Modal';
// o
import { Modal } from '@material-ui/core';
You can learn about the difference by reading this guide on minimizing bundle size.

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.

Component name

The name MuiModal can be used when providing default props or style overrides in the theme.

Props

NombreTipoPor defectoDescripción
children*elementA single child content element.
⚠️ Needs to be able to hold a ref.
open*boolfalseControl the popup` open state.
BackdropComponentelementTypeBackdropA backdrop component. This prop enables custom backdrop rendering.
BackdropPropsobjectProps applied to the Backdrop element.
classesobject
closeAfterTransitionboolfalseWhen set to true the Modal waits until a nested Transition is completed before closing.
componentelementType
components{ Root?: elementType }{}
componentsPropsobject{}
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.
disableAutoFocusboolfalseIf 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.
disableEnforceFocusboolfalseIf 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.
disableEscapeKeyDownboolfalseIf true, hitting escape will not fire the onClose callback.
disablePortalboolfalseThe children will be inside the DOM hierarchy of the parent component.
disableRestoreFocusboolfalseIf true, the modal will not restore focus to previously focused element once modal is hidden.
disableScrollLockboolfalseDisable the scroll lock behavior.
hideBackdropboolfalseIf true, the backdrop is not rendered.
keepMountedboolfalseAlways 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.
onBackdropClickfuncCallback fired when the backdrop is clicked.
onClosefuncCallback 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".
sxobject

The ref is forwarded to the root element.
Any other props supplied will be provided to the root element (native element).

CSS

Rule nameGlobal classDescripción
root.MuiModal-root
hidden.MuiModal-hidden

You can override the style of the component using one of these customization options:

Demos