1<ModalContenttitle="This is a small modal!"width="small">...</ModalContent>
2<ModalContenttitle="This is a default modal!">...</ModalContent>
3<ModalContenttitle="This is a large modal!"width="large">...</ModalContent>
4<ModalContenttitle="This is an extra large modal!"width="xlarge">...</ModalContent>
Design
Modals focus a customer's attention on a single task within an overlay which blocks the page beneath. They allow customers to concentrate on a subordinate task, without losing the context of the main task on the underlying page. Modals are used to: warn customers of something, request confirmation of something, or gather some information. Modals are purposefully disruptive, so their use should be kept to a minimum.
Modals are for all other purposes and are typically used to stop the customer in their tracks to undertake a sub-task, without losing the context of where they are. These can be easily dismissed with the primary button, hitting the X in the top right, tapping outside the modal or hitting escape.
Problem
As a customer I want to undertake a sub task to the main task I am undertaking.
As a designer, I don’t want the customer to leave the page they are on and risk losing any data, or remembering where they were up to, but they need to undertake a related sub task.
Solution
Present the customer with a general modal, with the appropriate content.
Guidance
Use for related sub tasks where you do not want your customer to lose the context of where they are.
Use to remove complex functionality from an already complex screen.
Restrict the screen to the sub task which then requires the user’s full attention.
Use a short, meaningful title and body content.
Provide sufficient details for the customer without being too verbose.
Use sentence case for the title and body content, with the exception of titles or names.
Use reverse pyramid writing, starting with the most important information first.
The primary action button should support the title, preferably using the same verb.
Avoid using a modal on a modal.
Accessibility features
When opneing a modal focus is set to the modal heading
Focus remains trapped in the modal when open, it is not possible to return to the underlying content by mouse or keyboard.
Within the modal focus cycles through all available interactive states.
When closing the modal focus is returned to the point from which the modal was opened.
A modal must have a heading, body content and footer actions.
Keyboard users can hit the escape key to close the modal.
Pointed device users can click the backdrop to close the modal.
A boolean that can set the visibility of the modal to open. Default is false and the modal is hidden by default until requested by the user.
size
oneOf: default | small | large
default
false
Sets the size of the modal content.
ModalContent component
Props for the ModalContent component
Property
Type
Default
Required
Description
title
string
true
The title of the modal, this must be a meaningful value that correctly describes the modal content.
width
oneOf: default | small | large | xlarge
default
false
Sets the size of the modal, this prop controls the width displayed. If not set "default" is output as the default setting.
ModalBody component
Props for the ModalBody component
Property
Type
Default
Required
Description
children
ReactNode
true
The content of the modal, the content is placed within a content stack and any content can be inserted.
ModalFooter component
Props for the ModalFooter component
Property
Type
Default
Required
Description
children
ReactNode
true
The actions of the modal that allow the user to commit to an action or dismiss and return to the underlying parent page.
ModalOpen component
Props for the ModalOpen component
Property
Type
Default
Required
Description
Button
Button component
true
A button element is required to fire the modal into a visible state, both the Button and IconButton components can be used.
ModalClose component
Props for the ModalClose component
Property
Type
Default
Required
Description
Button
Button component
true
A button element is required to fire the modal into a closed state, both the Button and IconButton components can be used. The ModalClose can wrap a Button component within the ModalFooter component.