Skip to main content

Modal

A modal is an element that shows a priority dialog above the current content, where the focus should be completely pointed to the information inside of it, blocking all elements underneath with an opaque overlay.

Example

Live Editor
Result
Loading...

Usage Rules

When setting the code to use a Modal, you will wrap the component tree with ModalProvider.

// App.js

import { ModalProvider } from '@adjust/components';

export default function() {
return (
<ModalProvider>
{...}
</ModalProvider>
);
}

Inside the ModalProvider scope your code has access to openModal() and closeModal() via ModalContext.

CloseModal() is a direct instruction with no arguments, where OpenModal() usage is shown on the first example. The CloseModal() function will also call any code passed via onClose property.

The ModalProvider does not receive any property itself, while the openModal function accepts all the properties documented below.

note

It is possible to close the Modal by pressing the ESC key, on the keyboard

Variants

Custom Content

It is possible to use an element and/or a React component as content for the Dialog, as shown on the next example:

Live Editor
Result
Loading...

Primary Action

The primary action primaryAction is optional. It will execute the code which is added to primaryAction.onClick and then automatically close the Modal as default.

  • Using closeOnPrimaryClick as Modal prop to prevent the Modal from closing after clicking on the primary button.
  • Using closeModal() in primaryAction.onClick to close the modal.

Secondary Action

The secondary action secondaryAction is optional. This action gives you freedom to decide either to close or not. If you want to close, make sure to call closeModal() inside your custom secondaryAction.onClick, just like the first example.

Sizes

It is possible to pick between three different widths of the modal's dialog: small, medium (default) and large.

You can see them on the following example:

Live Editor
Result
Loading...

Static Height

You can set the height of Modal content by adding prop staticHeight.

Live Editor
Result
Loading...

Update Modal

You can update existing Modal by using updateModal(). It will update the existing Modal props.

Live Editor
Result
Loading...

You can also overwrite all Modal props by passing true as the second argument in updateModal().

Live Editor
Result
Loading...

Examples

You can get the open state of the modal with isModalOpen from the ModalContext

Live Editor
Result
Loading...

Update loading state

You can update the loading state of a button by using updateModal().

Live Editor
Result
Loading...

Props

The object structure for individual modal items passed into openModal:

NameTypeDefault
title *
Title of the Modal's dialog
string
content *
Content of the Modal's dialog
ReactNode
primaryAction
Primary button for the Dialog component. See the Button component for more info
ButtonProps
secondaryAction
Secondary and optional button for the Dialog component. See the Button component for more info
ButtonProps
closeButtonAction
The handler will be called only on clicking Close button
(() => void)
onClose
The handler will be called when the Modal is closed
(() => void)
onUpdate
The handler will be called when the Modal is updated
((dialog: DialogComponentProps) => void)
size
Size of the Modal's dialog
"small" | "medium" | "large" | "x-large"
"medium"
closeOnPrimaryClick
Use this prop to prevent the Modal's dialog from closing after clicking on the primary button
boolean
true
staticHeight
Static height of Modal's content and support scrollable.
string
testId
Unique identifier for Pendo tagging to be translated into data-testid attribute on Modal Actions
string
* - the prop is required.