Modals focus a user's attention on one task via a window that sits on top of the page. They present critical information, which may or may not require user input, before continuing the workflow.
By design, modals interrupt a user's workflow. Modals disable the main content area and prevent users from returning to their previous workflow until they complete the modal task or dismiss the modal.
Modals are mostly used for noting errors (original purpose) but they can be used for alerts, confirmations and custom requirements.
Clicking the close icon in the upper right will close the modal without submitting user data.
Clicking the primary action button completes the task and closes the modal.
The secondary action offers a way for the user to back out and take no action. Clicking the secondary button closes the modal and returns the user to their previous context.
When triggered, the tab sequence is contained & keyboard focus is trapped within the modal. The primary window is inert and cannot be interacted with until the modal is dismissed.
The modal components include a WAI-ARIA role="dialog" and aria-modal="true" to indicate to assistive technologies that the window beneath is currently inert. Focus order, accessible names and programmatic relationships are dependent on the individual content within each modal. The element with ARIA role="dialog" includes both an aria-labelledby & an aria-describedby reference, which refer to the primary modal title & modal content respectively.
Headers should ask a single, clear question or communicate a single concise message. If the modal is informational or educational with no decision required, then the title can be a statement.
Avoid using "Are you sure" as a modal title. It's vague and users might not know what you're really asking. Instead, ask users the question you want them to answer using the specific action, e.g., Send payment?
Body text should clarify any consequences and explain options in simple terms.
Avoid including information that is unrelated to the decision or complicated descriptions of rare situations.
For informational modals, use the correct tone to match the nature of the message. For example, when seeking to prevent an error, UX text should be clear and straightforward.
Primary button text should state an unambiguous action that answers the question posed in the headline.
Make sure the question and the actions use the same words. Avoid using disjointed language. For example, if you ask, "Delete portfolio?" in the header, the primary CTA should also read "Delete."
Primary actions go on the right, dismissive or secondary actions on the left.
For modals that require a decision, use words that describe the literal action rather than something vague like Yes, OK or Sure.
Reserve "OK" for situations like acknowledgment modals, where you're simply asking the user to acknowledge the presented information.
The contrast ratio of textual elements against their background is above 4.5:1 as per WCAG 2.1 AA requirements. Non-textual content that needs to convey meaning (such as icons and keyboard focus visibility) has a contrast ratio of at least 3:1 with its adjacent colors. All content is visible and functional up to and including 400% without requiring scrolling in two dimensions.
This component has been validated to meet the WCAG 2.1 AA accessibility guidelines. However, changes made by the content author can affect accessibility conformance.
The simplest way to display a modal is to import <ModalNext> and its child components and display it using state in the parent component.
To implement business logic, set up a handler and pass it as onResolve. In the example above, we trigger different actions using with each button. You can run several operations in the callback function, and close the modal when you are ready.
Notice that <ModalHeader> takes a onClose callback which runs when the use clicks the X (close) button.
defines the layout to be used with a 'component' property set to either Flex or Grid and componentProperties to set properties for that layout component
isOpen
bool
Optional flag indicating whether the Modal is currently open
onAfterOpen
func
Callback function that, if provided, is called when the Modal dialog has been opened and is visible to the user
onAfterClose
func
Callback function that, if provided, is called when the Modal dialog has been close and is hidden from the user
onRequestClose
func
Callback function that, if provided, is called when the Modal dialog has been requested to be closed (either by clicking on overlay or pressing ESC)
closeTimeoutMS
number
Number indicating the milliseconds to wait before closing the modal.
contentLabel
IntlMessageShape
String indicating how the content container should be announced to screen readers
overlayClassName
string
The optional CSS class for the overlay for the Modal dialog
className
string
The optional CSS class for the the Modal dialog
shouldFocusAfterRender
bool
Optional flag indicating whether the Modal will autofocus to itself on open
shouldCloseOnOverlayClick
bool
When false will not close the dialog when the overlay is clicked.
shouldCloseOnEsc
bool
Optional flag indicating whether keyboard support for closing the Modal is available (via the ESC key)
shouldReturnFocusAfterClose
bool
Optional flag indicating if the Modal should restore focus to the element that had focus prior to its display.
parentSelector
func
Function that will be called to get the parent element that the Modal will be attached to.
The ModalNext component is the base component that should wrap the below components, and determines some of the overarching behaviors of the modal.
defines the content layout to be used with a 'component' property set to either Flex or Grid and componentProps to set properties for that layout component
defines the header layout to be used with a 'component' property set to either Flex or Grid and componentProps to set properties for that layout component
status
success, info, warning, error
The status of this modal. Either a 'success', 'info', 'warning', error'. Default to no status
The function to be called when the close button is clicked. If you do not set this function, the modal will not have a close (x) button in the corner.
The ModalHeader component should be used to display the top portion of the modal - the status color bar, the optional icon to the left of the title, and the title itself.
Defines the layout to be used with a 'component' property set to either Flex or Grid and componentProps property to set properties for that layout component.
autoFocus
bool
Causes focus to be drawn to the body of the modal on mount. Defaults to true.
The ModalBody component is a simple component that serves to wrap the content of the modal and should be placed after the ModalHeader
defines the layout to be used with a 'component' property set to either Flex or Grid (otherwise, will default to a div) and componentProperties to set properties for that layout component
The ModalFooter component is a simple component that serves to wrap the footer content of the modal and should be placed as the last component wrapped by ModalNext. You will usually wrap buttons within this component, but it does not restrict you if other components are necessary for the implementation.
ModalNextContext (modal provider) is the only way to create a modal in a micro frontend.
importReact,{ useContext }from'react'; import{ModalNextContext}from'@jutro/components'; // . . . create the callback function const{ showAlert }=useContext(ModalNextContext); constshowSomething=(msg)=>{ showAlert({ status:'success', title: messages.genericSuccessMessage, message: msg, }); }; // . . . and eventually <buttononClick={()=>showSomething('Surprise!')}> Click here to get a surprise </button>;
The Alert modal is a generic modal that will display a modal with a status color, optional icon, title, message and a confirm button. The results of the Alert modal can be captured as well (confirm or close (as a reject)).
importReact,{ useState, useContext }from'react'; import{ModalNextContext}from'@jutro/components'; constAlertModalExample=()=>{ const[result, setResult]=useState(null); const{ showAlert }=useContext(ModalNextContext); asyncfunctiontriggerAlert(){ const results =awaitshowAlert({ status:'info'/* status - 'info', 'warning', 'error', or 'success' */, icon:'gw-error-outline'/* icon - optional icon class name for the icon to display to the left of the title */, title: 'Test Alert'/* title - string/IntlMessageShape for the title of the alert */, message: 'Just testing an Alert!'/* message - string/IntlMessageShape for the message to display within the alert */, confirmButtonText: 'OK'/* confirmButtonText - string/IntlMessageShape for the text to appear on the confirm button */, }); setResult(`modal result was: ${results}`); } return( <div> <buttononClick={triggerAlert}>Show Alert Modal</button> <div>{result}</div> </div> ); };
The Confirmation modal is a generic modal that will display a modal with a status color, optional icon, title, message and a confirm and cancel button. The results of the Confirmation modal can be captured as well (confirm, cancel or close (as a reject)).
importReact,{ useState, useContext }from'react'; import{ModalNextContext}from'@jutro/components'; constConfirmationModalExample=()=>{ const[result, setResult]=useState(null); const{ showConfirm }=useContext(ModalNextContext); asyncfunctiontriggerConfirmation(){ const results =awaitshowConfirm({ status:'info'/* status - 'info', 'warning', 'error', or 'success' */, icon:'gw-error-outline'/* icon - optional icon class name for the icon to display to the left of the title */, title: 'Test Confirm Modal'/* title - string/IntlMessageShape for the title of the confirm modal */, message: 'Just testing a Confirmation Modal!'/* message - string/IntlMessageShape for the message to display within the confirm modal */, confirmButtonText: 'OK'/* confirmButtonText - string/IntlMessageShape for the text to appear on the confirm button */, cancelButtonText: 'Cancel'/* cancelButtonText - string/IntlMessageShape for the text to appear on the cancel button */, }); setResult(`modal result was: ${results}`); } return( <div> <buttononClick={triggerConfirmation}>Show Confirmation Modal</button> <div>{result}</div> </div> ); };
Custom modals can be implemented with the ModalNext, ModalHeader, ModalBody and ModalFooter components, and displayed using showModal from ModalNextContext similar to the usage above for the generic modals.
A new opt-in feature was introduced that disables automatic event publishing for the Modal component. You can enable this feature by adding JUTRO_DISABLE_AUTO_EVENTS_PUBLISHING=true to the .env file in the root of your Jutro application. When this is enabled, legacy components no longer publish events by default. For more information on events and how to set up new events, see the Events documentation.