Modal
A modal is best for focusing the user's attention on a small amount of content and prompting a decision, such as a confirmation. Use it to temporarily interrupt the current task and block interaction with the content below.
Each EuiModal needs a specific set of nested child components. You can omit some if needed, but do not change their order.
Modal vs flyout
If your modal content is complex or takes a long time to complete, consider using an EuiFlyout instead.
Components
Accessibility requirement
Use aria-labelledby={modalTitleId} to ensure the modal is announced to screen readers.
Default
Modals use an EuiOverlayMask to obscure content beneath.
Focus management
EuiModal manages focus for keyboard navigation and accessibility. This ensures users can navigate modal content effectively,
especially those using screen readers or keyboard-only navigation.
When a EuiModal is used, it will automatically:
- Move focus to the modal when opened
- Trap focus inside the modal while open
- Return focus to the trigger element when closed
Manual return focus control
Use focusTrapProps to customize the focus behavior:
tsx code block:<EuiModal focusTrapProps={{ returnFocus: (triggerElement) => { // Return true to use default behavior (focus triggerElement) // Return false to prevent default behavior if (customElement.current) { customElement.current.focus(); return false; } return true; }, }} />
Manually return focus when the trigger element is removed
If the trigger element is removed from the DOM before the modal closes, focus will be "lost" to the document body.
In this case, manually return focus to an appropriate element using focusTrapProps.returnFocus.
Confirm modal
Use the EuiConfirmModal to ask the user to confirm a decision. It is a contextual wrapper around EuiModal that provides some helpful props for filling in common modal pieces. By default, the button color indicates a positive or neutral action. Change the buttonColor property to danger to indicate a destructive action.
Loading and disabling confirm button
EuiConfirmModal supports being able to apply loading and disabled states to the confirm button with the confirmButtonDisabled and isLoading props respectively. This is helpful to indicate the fetching of data and/or to wait for a user's input before enabling the confirm action.
Usage
Configuring forms
Since the child components of EuiModal are required to be in a specific order, you can only wrap the contents within EuiModalBody with the <form /> element. You can then hook up your submit button inside EuiModalFooter by adding the id of the <form /> element to the form prop of the button.
Setting width
Modals start with a minimum width of 400px, just enough to display form rows. They will grow to fit the contents until it reaches the specified maxWidth, the default of which is set to the medium breakpoint.
If the modal is not growing wide enough to fit your contents, you can pass a specific style.width, just remember that modals will always shrink to fit the window width.
Confirming an action
Use a Modal when you need to interrupt a user and ask them to confirm an action.
Structure
- Title mandatory
- Whenever possible, frame it as a question that provides context for the action. Don't use "Are you sure?"
- Focus the question on what's important to the user and in a way that assumes intent from them. For example
Discard 7 changes?instead ofExit without saving? - Avoid including text variables in the title, especially for things users can input without character limits, or with long limits. This is often the case with object labels. For example,
Apply configuration changes?instead ofApply configuration changes to Loremipsum-dolorsitamet-consectetur-adipiscing-elit deployment?
- Body mandatory
- Cause optional
- If the context is important to know, add it.
- Consequences mandatory
- Let users know what happens if they continue.
- If possible, list the objects that may be impacted.
- Don't repeat the title.
- More information optional
- If necessary, anticipate user questions or need for help by including a link to a relevant source of information (like docs).
- Calls to action mandatory
- The main action confirms the question asked in the title.
- If there's enough space and it is relevant, include the number of impacted objects and their noun. For example
Invite 3 usersinstead ofSend invite. - Always provide a secondary CTA that allows users to leave the prompt without taking an action.
- Not all choices are binary. Add a third CTA when it makes sense for common that actions users would want to do.
- Make sure each CTA is explicit and not ambiguous with the other CTAs next to it.
Confirming a destructive action
Asking to confirm a delete or remove action follows the same principles as the default pattern, with 2 additions:
- The main CTA is extra clear on what is about to be deleted with a clear noun, in addition to visual clues (
color.dangertoken). - The body is unambiguous about what wonβt be recoverable after the action is confirmed.
- Optionally, and depending on the importance of the destructive action, you may include an extra confirmation within the body of the modal. If you do so, use something generic, such as "delete" or that users can copy easily that will remind them of what they are actually deleting.
Guidelines
A modal says βpay attention to me and nothing else.β
A modal title should be one line
The modal body will automatically scroll if the content gets too tall. Try to keep this from happening by keeping your content short and to the point.
The header sets the context
Short and sentence-case, the header should indicate what the modal is about.
The body is for a single task
This task should not require a lot of explanation or user interaction.
Buttons are right-aligned
The primary action is a filled button, and the secondary action is a link button. Labels should use strong action verbs.
Use a modal to focus on a single action
A modal can gather input necessary for continuing the current workflow. This type of modal works best for a short, focused task. Use input modals sparinglyβthey interrupt the user's workflow.
Save dashboard
Do:Β A save action is a good use case for a modal. The meaning is clear and the content is simple.
Add a team member
Step 1 of 3: the basics
Don't:Β Modals aren't the best design solution for multiple steps or complex user input. An in-page form is more appropriate.
Open a modal on a user action
Let a user action, such as a button click, open a modal. Don't open a modal from a toolbar actionβusers don't expect it.
Avoid scrolling content
Modal content should fit in a single view. If your modal has a lot of detail or a long list of items, consider a different solution, such as a form or a table.
Don't stack modals
Opening a modal on top of a modal might mean your workflow is too complex. Instead, use a component that supports multiple steps, such as a form or steps.
Use a modal to confirm an action
The most common use of modals in the EUI Framework is to confirm a user action. This modal should start with a question, give users enough information to make a decision, and restate the action in the button label.
Save changes before leaving?
If you don't save, your changes will be lost.
Do: