A modal is an overlay element which blocks interaction with elements outside it.
Usage
import { Modal } from '@console/nimbus-ui/core';Features
A modal consists of an overlay container element, and an underlay. The overlay contains a Dialog and the underlay is a transparent element that covers the rest of the screen behind the overlay, and prevents the user from interacting with the elements behind it.
- Styleable – Customizable animations and styles for overlay, modal, header, content, footer, and close button.
- Accessible – Hides content outside, closes on outside click or Escape key.
- Focus – Focused inside the modal on mount, returned to trigger on unmount.
- Scrolling – Disables page scrolling while modal is open.
- Header – Customizable and styleable header section.
- Footer – Customizable and styleable footer section for actions.
- Close Button – Built-in, styleable close button for dismissing the modal.
- Dismissable – Optionally dismissable by close button or outside click.
Examples
Auto Focus
When you open the modal you can use the autoFocus prop on most components to toggle focus programatically.
No Title
The Modal.Title component is optional. If not provided you must provide an aria-label to the Modal for accessibility.
Size
The sizes prop control the size of the modal sm | md | lg | cover
Placement
The modal is placed vertically in the center by default. Use the placement prop to switch between top | center | bottom.
Inside Scroll
The modal had an internal scroll that allows the user to scroll Body.
Use Modal.Header and Modal.Footer to create sticky titles & actions.
Loading
Loading states can be achieved by removing the close buttons and setting isDismissable to false
Controlled
Most (but not all) aspects of the Modal can be controlled. This example shows controlling the isOpen prop being controlled.
Multiple Modals
This story demonstrates how to manage multiple modals within a single component. The first modal contains a button that opens a second modal, which is controlled via state. This approach is useful for workflows requiring sequential user input, such as multi-step forms or confirmation dialogs.
API
Modal
Root component that takes a Modal.Header, Modal.Close, Modal.Content and Modal.Footer as children.
<Modal>
<Modal.Close>...</Modal.Close>
<Modal.Header>...</Modal.Header>
<Modal.Content>...</Modal.Content>
<Modal.Footer>...</Modal.Footer>
<Modal>| Prop | Type | Default | Description |
|---|---|---|---|
| placement | enum | center | |
| size | enum | md |
React Aria