dialogs
Modal
A window overlaid on the primary view, rendering the underlying content inert.
Features
- Keyboard accessible
- Focus is automatically trapped
- Manages screen reader announcements with Title
- Themes ready
Overview
A Modal is a window overlay that communicates or provides an action within the same process. Modals are a type of dialog that are used to provide important information or ask for user input necessary to complete a user's workflow. Modals should be used sparingly and only in situations where they provide clear value and enhance the user's experience. When used appropriately, a modal can be an effective way to grab the user's attention, provide important information, and guide them through a specific task or workflow.
Anatomy
import { Modal } from "@wonderflow/react-components";
export default () => {
const [visible, setVisible] = useState<boolean>(false);
return (
<ResponsiveProvider>
<Button onClick={() => setVisible(true)} >Show Modal</Button>
<Modal
isVisible={visible}
onCloseModal={() => setVisible(false)}
title= 'Delete account?'
subtitle= 'This action cannot be undone'
hideHeaderBorder
hideFooterBorder
content={<Text>...</Text>}
primaryAction={<Button>Delete</Button>}
secondaryAction={<Button>Cancel</Button>}
/>
</ResponsiveProvider>
)
};
Design Guidelines
When to use
Use to inform the user of critical information about their current workflow.
Use when you need to ask a confirmation from a user before proceeding.
Use when the user is required to take an action.
To provide context and guidance for a specific task or workflow, such as providing instructions for completing a form or setting up an account.
When not to use
For information that is not related or relevant to the current user flow. This can be distracting and may interfere with the user's overall experience.
To display non-critical or secondary information, such as help text tips, or product recommendations. In these cases, a tooltip or a popover component may be more appropriate.
To force the user to take an action or make a decision.
To display complex forms or large amounts of information.
For navigation.
Best practice
Keep the content relevant: Include only the essential information and actions that are required to complete the current task. Avoid overloading the modal with unnecessary content. Use modals sparingly: Modals should only be used when it's necessary to temporarily interrupt the user's workflow to gather important information or to convey a critical message.
Avoid displaying a modal over another modal. Instead, consider adding the additional information to the existing modal content or directing users to a new screen. Avoid using nested modals. If a confirmation modal is required to approve a task in the first modal, the first task should not be performed in a modal.
Sizes
The modal is available in three sizes: 720px (large), 600px (medium) and 480px (Small).
Use the large size for more complex workflows. Regardless of the size selected, the Modal component's height grows dynamically with the content.
On smaller screens with a width of less than 480px pixels or using a small screen size breakpoint, the Modal component expands to the full width of the screen, and its footer and actions are fixed to the bottom.
Custom Modal
In order to create custom Modal
components, be sure to use the three sub-components Modal.Header
, Modal.Content
, and Modal.Footer
to keep the Modal structure consistent and pass custom elements as children.
import { Modal } from "@wonderflow/react-components";
export const CustomModal = () => {
const [visible, setVisible] = useState(false);
return (
<ResponsiveProvider>
<Button onClick={() => setVisible(true)} >Show Modal</Button>
<Modal
isVisible={visible}
onCloseModal={() => setVisible(false)}
>
<Modal.Header>...</Modal.Header>
<Modal.Content>...</Modal.Content>
<Modal.Footer>...</Modal.Footer>
</Modal>
<ResponsiveProvider>
);
};
API Reference
Modal
isVisible
*boolean
false
onCloseModal
*function
title
string
subtitle
string
hideCloseButton
boolean
hideHeaderBorder
boolean
content
ReactNode
primaryAction
PolymorphicButton
secondaryAction
PolymorphicButton
tertiaryAction
ReactNode
alignActionCenter
boolean
alignContentCenter
boolean
isLoading
boolean
size
enum
medium
theme
enum
light
preventCloseOnClickOutside
boolean
Modal.Header
hideCloseButton
boolean
hideBorder
boolean
theme
enum
"light"
Modal.Content
alignContentCenter
boolean
theme
enum
"light"
Modal.Footer
hideBorder
boolean
theme
enum
"light"
Accessibility
Adheres to the dialog
role requirements.
Keyboard interactions
Name | Description |
---|---|
tab | Moves focus to the next focusable element inside the modal |
shif + tab | Moves focus to the previous focusable element inside the modal |
esc | Close the modal and move the focus on the trigger element |