Displays a dialog with a custom content that requires attention or provides additional information.
NextUI exports 5 modal-related components:
- Modal: The main component to display a modal.
- ModalContent: The wrapper of the other modal components.
- ModalHeader: The header of the modal.
- ModalBody: The body of the modal.
- ModalFooter: The footer of the modal.
When the modal opens:
- Focus is bounded within the modal and set to the first tabbable element.
- Content behind a modal dialog is inert, meaning that users cannot interact with it.
By default the modal can be closed by clicking on the overlay or pressing the Esc key.
You can disable this behavior by setting the
isDismissable prop to
By default the modal is centered on screens higher than
sm and is at the
bottom of the screen on mobile. This placement is called
you can change it by using the
bottom-centerpositions mean that the modal is positioned at the top / bottom of the screen on mobile and at the center of the screen on desktop.
You can use the
scrollBehavior prop to set the scroll behavior of the modal.
- inside: The modal content will be scrollable.
- outside: The modal content will be scrollable and the modal will be fixed.
Modal handles the focus within the modal content. It means that you can use the modal with
form elements without any problem. the focus returns to the trigger when the modal closes.
Note: You can add the
autoFocusprop to the first
Inputcomponent to focus it when the modal opens.
Modal component has a
backdrop prop to show a backdrop behind the modal. The backdrop can be
blur. The default value is
You can customize the backdrop by using the
Modal offers a
motionProps property to customize the
Learn more about Framer motion variants here.
- wrapper: The wrapper slot of the modal. It wraps the
- base: The main slot of the modal content.
- backdrop: The backdrop slot, it is displayed behind the modal.
- header: The header of the modal, it is displayed at the top of the modal.
- body: The body of the modal, it is displayed in the middle of the modal.
- footer: The footer of the modal, it is displayed at the bottom of the modal.
- closeButton: The close button of the modal.
You can customize the
Modal component by passing custom Tailwind CSS classes to the component slots.
Modal has the following attributes on the
- data-open: When the modal is open. Based on modal state.
When the modal is dismissable. Based on
- Content outside the modal is hidden from assistive technologies while it is open.
- The modal optionally closes when interacting outside, or pressing the Esc key.
- Focus is moved into the modal on mount, and restored to the trigger element on unmount.
- While open, focus is contained within the modal, preventing the user from tabbing outside.
- Scrolling the page behind the modal is prevented while it is open, including in mobile browsers.
|children*||The content of the modal. It's usually the ||-|
|size||The modal size. This changes the modal |
|radius||The modal border radius.|
|shadow||The modal shadow.|
|backdrop||The modal backdrop type.|
|scrollBehavior||The modal scroll behavior.|
|placement||The modal position.|
|isOpen||Whether the modal is open by default (controlled).||-|
|defaultOpen||Whether the modal is open by default (uncontrolled).||-|
|isDismissable||Whether the modal can be closed by clicking on the overlay or pressing the Esc key.|
|isKeyboardDismissDisabled||Whether pressing the Esc key to close the modal should be disabled.|
|shouldBlockScroll||Whether the modal should block the scroll of the page on open.|
|hideCloseButton||Whether to hide the modal close button.|
|closeButton||Custom close button to display on top right corner.||-|
|motionProps||MotionProps||The props to modify the framer motion animation. Use the |
|portalContainer||The container element in which the overlay portal will be placed.|
|disableAnimation||Whether the modal should not have animations.|
|classNames||Allows to set custom class names for the modal slots.||-|
|onOpenChange||Handler that is called when the modal's open state changes.|
|onClose||Handler that is called when the modal is closed.|
export type MotionProps = HTMLMotionProps<"div">; // @see https://www.framer.com/motion/