Modal
The Modal component lets you create dialogs, popovers, lightboxes, and other elements that force the user to take action before continuing.
Modal API
Import
import { Modal } from '@mui/base/Modal';
// or
import { Modal } from '@mui/base';Props
Props of the native component are also available.
When set to true the Modal waits until a nested Transition is completed before closing.
Type:
boolDefault:
falseAn 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.
Type:
HTML element | funcIf 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.
Type:
boolDefault:
falseIf 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.
Type:
boolDefault:
falseIf true, hitting escape will not fire the onClose callback.
Type:
boolDefault:
falseThe children will be under the DOM hierarchy of the parent component.
Type:
boolDefault:
falseIf true, the modal will not restore focus to previously focused element once modal is hidden or unmounted.
Type:
boolDefault:
falseAlways 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.
Type:
boolDefault:
falseCallback fired when the component requests to be closed. The reason parameter can optionally be used to control the response to onClose.
Type:
funcSignature:
function(event: object, reason: string) => voideventThe event source of the callback.reasonCan be:"escapeKeyDown","backdropClick".
The props used for each slot inside the Modal.
Type:
{ backdrop?: func | object, root?: func | object }Default:
{}The components used for each slot inside the Modal. Either a string to use a HTML element or a component.
See Slots API below for more details.
Type:
{ backdrop?: elementType, root?: elementType }Default:
{}The
ref is forwarded to the root element.Slots
To learn how to customize the slot, check out the Overriding component structure guide.
You can override the style of the component using one of these customization options:
- With a global class name.
- With a rule name as part of the component's
styleOverridesproperty in a custom theme.
CSS classes
These class names are useful for styling with CSS. They are applied to the root slot when specific states are triggered.
Class name applied to the root element if the Modal has exited.